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

What are the situations when jvm is closed in java?

PHPz
Release: 2023-05-21 14:55:06
forward
1528 people have browsed it

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){
       
       }
     }
 });
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template