将SIGTERM发送到JVM是否安全 [英] Is it safe to send SIGTERM to JVM

查看:218
本文介绍了将SIGTERM发送到JVM是否安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然JVM将将SIGTERM和类似信号转换为关闭钩子
许多服务关闭脚本使用TCP端口启动关闭。 (例如Tomcat的关闭端口, Java Service Wrapper ,JBoss的管理界面等)

Although JVM will translate SIGTERM and similar signals to shutdown hooks, many service shutdown scripts use a TCP port to initiate a shutdown. (e.g. Tomcat's shutdown port, Java Service Wrapper, JBoss' management interfaces, etc.)

所以我认为不鼓励使用信号和关闭钩子来优雅地关闭java服务,直到我发现播放!框架是使用关闭挂钩来管理服务生命周期,并且 play dist 生成的启动脚本假定信号将被发送到JVM的PID。

So I thought using signals and shutdown hooks to gracefully shutdown java services is discouraged, until I found that Play! framework is managing the service lifecycle with shutdown hooks and the startup scripts generated by play dist assumes that a signal will be sent to the JVM's PID.

我知道信号是依赖于平台的,并且使用TCP端口是一种以跨平台方式管理服务的简单且可扩展的方式,但我想知道它是多么安全当我依赖SIGTERM并关闭钩子作为服务关闭的主要方法时,我需要考虑哪些风险。

I know that signals are platform-dependent and using a TCP port is a simple and extensible way to manage services in a cross-platform manner, but I would like to know how safe it is and what risks I need to consider, when I rely on SIGTERM and shutdown hooks as a primary method for service shutdown.

推荐答案

只要Java服务明智地使用ShutdownHooks进行有序终止,将SIGTERM发送到JVM进程就没有问题。例如。我们使用SIGTERM作为在我们的大型高负载生产系统(运行80个不同Java应用程序的5000多台服务器)中启动应用程序关闭的主要方法。

As long as Java service uses ShutdownHooks wisely for orderly termination, there is no problem in sending SIGTERM to JVM process. E.g. we use SIGTERM as a primary method for initiating an application shutdown in our large high-load production system (5000+ servers running 80 different Java applications).

这篇关于将SIGTERM发送到JVM是否安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆