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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:51:02+00:00 2026-05-29T21:51:02+00:00

I am trying to provide a very simple Do you wish to save this

  • 0

I am trying to provide a very simple “Do you wish to save this document?” dialog upon shutdown of my application.

I have used a WindowAdapter to do this. This works perfectly if the application is closed using any GUI action (clicking the CLOSE button, closing from the task bar, closing from the Task Manager using End Task).

However, when the user logs off or kills the application process, the JVM application receives a termination signal directly. It closes any AWT resources without user confirmation and without calling the WindowAdapter. Using a ShutdownHook, it is not possible to have any GUI interaction, because the AWT Event Dispatch Thread has already been stopped.

So far I have found multiple ways to work around this problem:

  • Use JNI or JNA to catch the terminate signal before it reaches the AWT subsystem.
    • Needs separate code for every operating system.
  • Use sun.misc.SignalHandler to catch the terminate signal.
    • Uses a SUN proprietary interface. Not guaranteed to work on other VM’s.
  • Use SWT to catch the terminate signal before it reaches the AWT subsystem.
    • Well-maintained interface, but I hate pulling in SWT just to resolve this small problem.
  • Save the user data to a temporary file and treat the clean-up when the program is launched again.

Is there another, better way to fix this? It seems strange there is no standard way to implement something so basic and elementary. Can’t I boot up the AWT subsystem again in some way?

  • 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-29T21:51:03+00:00Added an answer on May 29, 2026 at 9:51 pm

    The host platform owns the JVM running your application. On Mac OS X you can use OSXAdapter, discussed here. Other systems may have a similar mechanism. One useful defensive measure is to use java.util.prefs.Preferences to record clean-up information. It’s platform-independent and typical implementations offer best-effort retention for a given platform.

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

Sidebar

Related Questions

I'm trying to learn how to profile perl memory. I have a very simple
I'm trying to build a very simple location-based app and I have all of
I am trying to provide a simple RESTful API to my ASP MVC project.
This is the situation. I'm trying to provide a service where someone embedds an
I'm trying to write a plugin system to provide some extensibility to an application
I was trying to create a very simple MySQL event and realized the action
I am currently trying to write a very simple app that sends an object
I'm trying to build a very simple bit of javascript that reads and displays
I'm trying to do something very simple, get the top result URL of a
I am trying to get jscrollpane working on a very simple page, but for

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.