donaricano-btn

Shutdown Hook

- Shutdown hook can be used to perform cleanup resource or save the state when JVM shuts down normally or abruptly

- clean resource means closing log file, sending some alerts...]

- If you want to execute some code before JVM shuts down, use shutdown hook


1. When does the JVM shut down?

- user presses ctrl+c on the command prompt

- System.exit(int) method is invoked

- user logoff

- user shutdown etc..


2. The addShutdownHook(Thread hook) mehtod

- addShutdownHook() method of Runtime class is used to register the thread with the Virtual Machine


3. Simple Example

 

'Back-End > Java_1' 카테고리의 다른 글

[Java] JDK 환경변수 설정(configure) - Window10  (0) 2016.11.13
[Java] Garbage Collection  (0) 2016.10.11
[Java] Thread pool  (0) 2016.10.10
[Java] Daemon Thread  (0) 2016.10.10
[Java] Thread Priority  (0) 2016.10.07
블로그 이미지

리딩리드

,