Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7030153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:37:56+00:00 2026-05-28T00:37:56+00:00

When do I actually need call this method Runtime.getRuntime().addShutdownHook() and when or why I

  • 0

When do I actually need call this method Runtime.getRuntime().addShutdownHook() and when or why I need to shutdown my application. Could anyone please explain me this by giving some example.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:37:56+00:00Added an answer on May 28, 2026 at 12:37 am

    As far as I know, I will explain this below. You can google it and find lot of information too.

    addShutdownHook() will register some actions which is to be performed on a Program’s termination. The program that you start ends in two ways:

    1. the main thread (Root) ends its running context;
    2. the program meets some unexpected situation, so it cannot proceed further.

    If you add a ShutdownHook, the hook will start a thread that will start running at time of termination only. For example:

     Runtime.getRuntime().addShutdownHook(new Thread() {
          public void run() {
            System.out.println("Running Shutdown Hook");
          }
        });
    

    will print a Running Shutdown Hook at the time of program termination at any point. You might even call a System.exit(0).

    For examples, you can google, there are enough of them. And the question ‘When should you use this’ is like asking ‘What does catch do in a try-catch statement’.

    You might have many situations like:

    • your program had created many temporary files in filesystem you want to delete it;
    • you need to send a distress signal to another process/machine before terminating;
    • execute any clean-up actions, logging or after-error actions on unexpected behaviours.

    All this will be needed for some point of time.

    For examples you can go in here Example 1 or Example 2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method that I need to call and use in my application,
I need a help from ur side. Actually I need to call a method
Let's say, hypothetically (read: I don't think I actually need this, but I am
I'm getting pretty big input string into my method, but what I actually need
I currently convert an application to use CreateProcessW() instead of Runtime.exec() as I need
My question is similar to this one: need to call soap ws without wsdl
EDIT: This method actually works great and I asked it then found the solution
I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using
Actually We are doing thesis work where we need to make 10 voip phones
I need a table where rows are actually 2 rows tables, a nested table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.