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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:59:54+00:00 2026-05-12T11:59:54+00:00

I have a standalone application in which I have to prompt the user with

  • 0

I have a standalone application in which I have to prompt the user with an confirm dialog box to save the changes made by him when he tries to shutdown the system by start-->shutdown.

I came to know that by using signalhandlers we can do it.
Can some one help me how to use signal handlers

  • 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-12T11:59:54+00:00Added an answer on May 12, 2026 at 11:59 am

    Update May 2012 (2 and half years later)

    Trejkaz comments:

    On current versions of Java this signal handling code fails because the “INT” signal is “reserved by the VM or the OS”.
    Additionally, none of the other valid signal names actually fire when something requests the application to close (I just painstakingly tested all of the ones I could find out about…)
    The shutdown hook mostly works but we find that in our case it isn’t firing, so the next step is obviously to resort to registering a handler behind the JVM’s back

    The chapter “Integrating Signal and Exception Handling” of the “Troubleshooting Guide for HotSpot VM” mentions the signals “SIGTERM, SIGINT, SIGHUP” only for Solaris OS and Linux.
    Only Exception Handling on Windows are mentioned.


    Original answer (Sept 2009)

    a ShutdownHook should be able to handle that case

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        public void run() {
            // what you want to do
        }
    }));
    

    (with caveats)
    See also:

    • Java signal handling and termination (link is dead, see archive or mirror)
    • java exit signal handling:

    as an illustration of simple signal handling:

    public class Aaarggh {
      public static void main(String[] args) throws Exception {
        Signal.handle(new Signal("INT"), new SignalHandler () {
          public void handle(Signal sig) {
            System.out.println(
              "Aaarggh, a user is trying to interrupt me!!");
            System.out.println(
              "(throw garlic at user, say `shoo, go away')");
          }
        });
        for(int i=0; i<100; i++) {
          Thread.sleep(1000);
          System.out.print('.');
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hai I have developed a standalone application in which when an user logs in,
Hi I have an Standalone application in which when an user logs in a
I have created an standalone application in which i want that when the user
I need to write a standalone Java application which will have a embedded HTTP
I have designed a standalone application using swings which can read data from HID
I have some code which is a standalone java application comprising of 30+ classes.
I have written standalone application which is working in Windows Azure as startup task.
I have a standalone java application, which uses JPA for its persistence. Right now
I have developed a standalone application using java, in which I am executing an
I have a standalone Java application written with Apache Camel which I want to

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.