Sample application to demonstrate the threads to be shutdown gracefully
mvn clean package
cd target
java -jar <jarname>
(to run as background process, check below items)
- While stopping process from IDE console, it won't executing shutdown hook (tested with Eclipse)
- While stopping process using
TASKKILL /F
command from Windows, it won't executing shutdown hook (it's not stopping without using/F
option) - While stopping process using
Ctl + C
from Windows, it will execute the shutdown hook - While stopping process using
kill <PID>
from Linux, it will execute the shutdown hook (not thekill -9
)
java -jar test.jar
javaw -jar test.jar
nohup java -jar test.jar &
C:
cd "C:\Program Files\Java\jdk1.8.0_162\bin"
jps -lv
TASKKILL /F /<PID>
(forcefully)
TASKKILL /<PID>
(gracefully, this way is not working to kill java background process)
ps aux | grep java
kill -9 <PID>
(forcefully)
kill <PID>
(gracefully)