Nikem
Nikem

Reputation: 5784

javaagent, systray and shutdown

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?

Upvotes: 1

Views: 935

Answers (2)

Nikem
Nikem

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

Bruno Grieder
Bruno Grieder

Reputation: 29834

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

SystemTray.getSystemTray( ).remove( trayIcon );

Upvotes: 0

Related Questions