1

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?

4

2 に答える 2

1

完全を期すために、この問題をどのように解決したかを次に示します。

表示可能な AWT コンポーネントを定期的にチェックするジョブで別のデーモン スレッドを開始しました。それらの 1 つだけが残っていて、それが私のシステム トレイ アイコンである場合は、それを削除します。これにより、AWT サブシステムが終了し、アプリケーション全体が正常に終了します。

于 2012-12-19T06:54:31.970 に答える
0

Runtime.getRuntime().addShutdownHook()呼び出すシャットダウンフック()を追加してみてください

SystemTray.getSystemTray( ).remove( trayIcon );

于 2012-03-26T14:30:42.440 に答える