Home  >  Article  >  Java  >  What are the situations when jvm is closed in java?

What are the situations when jvm is closed in java?

PHPz
PHPzforward
2023-05-21 14:55:061490browse

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete