I am doing some Poc for Stilts stomp server. Need to prevent server jvm termination and do it through another jvm. Here is a code snippet
public static void main(String[] args) {
try {
log.debug("Starting server...");
StompServer<MockStompProvider> server = new StompServer<MockStompProvider>();
server.setStompProvider( new MockStompProvider() );
server.addConnector( new InsecureConnector() );
server.start();
while (true) {
Thread.sleep(200000);
}
} catch (Exception ex) {
log.error("Exception ", ex);
}
}
There are two requirements.
- Is there any other way to prevent termination the above jvm without using
while
loop. - I would like to stop jvm using command like
java -jar server.jar -- stop
for example a server like jetty. Jetty use ports and listens for signal for stop request. Is there any simple way.
One option for second one can be using a AnchorFile, create file when start jvm and monitor for file existence and using stop jvm remove that file.