开发者

SWT: cleaning up before application exit

What is the best way for an SWT application to clean up resources before application exit? I see two options:

1) Add a DisposeListener to main window (or better, to the Display). Will it get run if an uncaught excep开发者_如何学Pythontion happens?

2) Use a shutdown hook. Any problems to be aware of there which aren't mentioned in Design of the Shutdown Hooks API?


If an uncaught exception happen, you may end up with java.lang.RuntimeException: Widget disposed too early! exception:

This is usually caused by one of the other exceptions, especially on close, and often times the "disposed to early" errors are listed before the exception that caused them. i.e.

  1. workbench is closing
  2. one part thows an error that can't be caught.
  3. all the following parts aren't closed, and so generate this error
  4. the error that cause the problem percolates up to the top of the stack and is printed out.

In your case, I am not sure how it would affect your Listener, so a shutdown hook might be a fail-safe, provided it still can access resources to dispose (which may not be always the case).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜