Home >Java >javaTutorial >What are the situations when jvm is closed in java?
1. JVM shutdown
(1) Normal shutdown
All non-daemon thread execution ends
System.exit(0)
ctrl c
kill -15 SIGTERM signal
(2) Abnormal shutdown
RuntimeExcetion
OOM
(3) Forced shutdown
kill -9 SIGKILL signal
Runtime.halt()
Power off
System shutdown
System crash
2. Example
public void start(){ Runtime.getRuntime().addShutdownHook(new Thread(){ public void run(){ try{ LogService.this.stop(); }catch(InterruptedException){ } } }); }
The above is the detailed content of What are the situations when jvm is closed in java?. For more information, please follow other related articles on the PHP Chinese website!