Is it safe to send SIGTERM to JVM

六月ゝ 毕业季﹏ 提交于 2019-11-30 16:57:37

问题


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.)

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.

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.


回答1:


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).



来源:https://stackoverflow.com/questions/24728586/is-it-safe-to-send-sigterm-to-jvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!