简体   繁体   English

停止正在读取 MQ 的 nohup Java 进程

[英]Stopping a nohup Java process that is reading MQ

I have a java process that runs in nohup which reads the message from MQ continuously.我有一个在 nohup 中运行的 java 进程,它不断地从 MQ 读取消息。 What is the best way to stop that process in a controlled manner instead of killing the process to stop abruptly.以受控方式停止该进程而不是终止进程以突然停止的最佳方法是什么。

Currently I have coded to match the incoming message with "STOP_THE_PROCESS" string and if it matches it will stop the process.目前,我已编码以将传入消息与“STOP_THE_PROCESS”字符串匹配,如果匹配,它将停止该过程。 Is there any other better way?还有其他更好的方法吗?

You can add so called 'shutdown port' to your java application: application will listen on specific port for shutdown command and terminate gracefully on receive.您可以向 Java 应用程序添加所谓的“关闭端口”:应用程序将在特定端口上侦听关闭命令并在接收时正常终止。

Apache Tomcat uses this approach, with dedicated tcp socket. Apache Tomcat 使用这种方法,具有专用的 tcp 套接字。

Sample JMX-based implementation: https://dzone.com/articles/java-jmx-shutdown-example基于 JMX 的示例实现: https : //dzone.com/articles/java-jmx-shutdown-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM