Reputation: 5784
We write a java agent, which among other things provides some sort of GUI using java.awt.TrayIcon . When we use this agent in, e.g. Tomcat, we have the following problem:
Now the question is, what should we do, to allow an application to shut down? Is it possible to make AWT Event dispatch thread daemon? Is there shutdown hooks for agents? Anything else?
Upvotes: 1
Views: 935
Reputation: 5784
For the sake of completeness, here is how I have solved this problem:
I have started another daemon thread with the job, that periodically checks for displayable AWT components. If there is only one of them left, and that is my systray icon, then I remove it. This allows AWT subsystem to exit resulting in normal exiting of the whole application.
Upvotes: 1
Reputation: 29834
You could try adding a shutdown hook (Runtime.getRuntime().addShutdownHook()
) which calls
SystemTray.getSystemTray( ).remove( trayIcon );
Upvotes: 0