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 8753395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:25:00+00:00 2026-06-13T13:25:00+00:00

I have developed a Java online distributed application which usually active all the time

  • 0

I have developed a Java online distributed application which usually active all the time (not GUI).

I am interested to perform some steps before the shutdown in case the administrator is interested in such shutdown.

I know that CTRL^C stops the JVM, i wonder if i can hook CTRL^C and execute some additional operations before JVM shutdown, or add some hook to a CTRL^D event in order to do the same thing.

I almost sure there is a post somewhere describes similar questions , and i would appreciate links to such posts.

i am not interested in any third party external jars or any JNI solution.

I will appreciated a code example snippet if there is no post discussing the same question.

Additional constraint: This solution should work both for UNIX and Windows.

Edit

One solution that was proposed here is the use of Runtime.getRuntime().addShutdownHook(new Thread() {})

As far as i understand a new thread is created which will listen and wait to the shutdown event to happen.

  1. I wonder if somehow i can signal the main thread that a shutdown occurred ( I have a distributed system as i mentioned , and i need to inform each single thread of such event)?

  2. May i add multiple thread to listen for this event?

  • 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-06-13T13:25:01+00:00Added an answer on June 13, 2026 at 1:25 pm

    To react to CTRL+C you have to add a shutdown hook:

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            System.out.println("I'll be back!");
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a java application which run's perfectly in local server. But When
I have developed java application which is actually stored at d drive.I have imported
I have developed a java application which takes a screenshot using robot (presses Print
I have developed a GUI java application. It has login page for user authentication.
I have developed a java swing client-server application. The server has many services like
I have developed a number of classes which manipulate files in Java. I am
We have our own custom calendar in our portal which is developed in Java.
I have developed a Java socket server connection which is working fine. When started
I have developed a java 1.4 web application.Application is deployed on jboss(tomcat). suppose my
I have developed a java web application using JSF 2.0(Facelets) on GlassFish 3.1.1 with

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.