gpt4 book ai didi

java - SWT:应用程序退出前清理

转载 作者:行者123 更新时间:2023-11-30 11:59:02 25 4
gpt4 key购买 nike

SWT 应用程序在应用程序退出前清理资源的最佳方式是什么?我看到两个选项:

1) 添加一个 DisposeListener 到主窗口(或者更好的是,添加到 Display)。如果发生未捕获的异常,它会运行吗?

2) 使用 shutdown hook . Design of the Shutdown Hooks API中没有提到的任何需要注意的问题?

最佳答案

如果发生未捕获的异常,您可能会以 java.lang.RuntimeException: Widget disposed too early! 结束。异常:

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.

在您的情况下,我不确定它会如何影响您的监听器,因此关闭 Hook 可能是故障安全的,前提是它仍然可以访问要处理的资源(情况可能并非总是如此)。

关于java - SWT:应用程序退出前清理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2760416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com