Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do graceful shutdown/termination of java processes?

I am running some java apps and I need to shutdown/close all apps gracefully from windows bat script. So my question is:
How to invoke shutdown hook by windows bat script and gracefully shutdown java program.

Any suggestion is appreciated. Thanks in advance.

like image 727
SmartSolution Avatar asked Dec 16 '22 11:12

SmartSolution


1 Answers

Take a look at the addShutdownHook method in the Runtime class.

Runtime.getRuntime().addShutdownHook(...);

UPDATE: As per comment below, there is a command TASKKILL in the windows shell that is similar to the *nix kill command. For instance TASKKILL /IM java.exe would terminate all java processes. TASKLIST can be used to find all running processes. Using this in conjunction with a shutdownhook should give you the graceful possibilites required.

like image 168
pap Avatar answered Dec 19 '22 01:12

pap