Java Close Hook

Source: Internet
Author: User

Java Close Hook

In a Java program, you can turn off the resource when the program exits by adding a close hook.
Use Runtime.addshutdownhook (Thread hook) to add closure hooks to the JVM

     Public void Addshutdownhook (Thread hook) {        = System.getsecuritymanager ();         if NULL {            sm.checkpermission (new runtimepermission ("Shutdownhooks"));        }        Applicationshutdownhooks.add (hook);    

Shutdownhook (Thread hook) method, you can register a JVM closed hook, this hook can be called in the following several scenarios:
1) Program Exit normally
2) use System.exit ()
3) interrupts triggered by the terminal using CTRL + C
4) System shutdown
5) Kill the process using the kill PID command

When you do a big task, shut down the JVM. This time, at least the small task that is currently split is completed before it can be closed.

such as bulk queries

Java Close Hook

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.