Question

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:

  1. User starts Tomcat using shell script
  2. Our agent adds icon to systray
  3. User shuts Tomcat down using shell script
  4. AWT Event thread sees, that there is still displayable component, systray icon, and does not quit
  5. As AWT Event thread is non-daemon thread, whole application cannot quit

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?

Était-ce utile?

La solution

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.

Autres conseils

You could try adding a shutdown hook (Runtime.getRuntime().addShutdownHook()) which calls

SystemTray.getSystemTray( ).remove( trayIcon );

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top