Reputation: 103
Details: I have a JAVA application that takes some time to shutdown. There is a call to close a port, that takes a really long time. I want to add a dialog box that indicates to the user that the application is shutting down. Normally, I would create a dialog box, start a thread to do long work and close dialog, then display the dialog. Once the work is done, the dialog would be close. This does not work for shutting down an application because it seems the window listener closes all windows (kind of makes sense, it supposed to do that). I'm not sure a way around this.
Code:
public void windowClosing(WindowEvent we)
{
shutDown();
}
public void shutdown()
{
final JDialog dialog = createDialog();
Thread t = new Thread
{
public void run()
{
saveProperties();
ClosePort();
dialog.setVisible(false);
System.exit(0);
}
};
t.start();
dialog.setVisible(true);
}
Upvotes: 0
Views: 124
Reputation: 109547
t.setDaemon(true);
as daemon threads stay alive even if the rest is gone.
Upvotes: 1