我最近将我的计算机更新为更强大的计算机,配备了四核超线程处理器(i7),因此可以提供大量真正的并发性.现在我在退出()我正在开发的应用程序(使用Swing GUI)时偶尔会出现以下错误System.exit(0):
Exception while removing reference: java.lang.InterruptedException
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134)
at sun.java2d.Disposer.run(Disposer.java:125)
at java.lang.Thread.run(Thread.java:619)
Run Code Online (Sandbox Code Playgroud)
好吧,鉴于它开始发生在具有更多并发能力的硬件上,并且它与线程有关,并且它偶尔发生,它显然是某种时间性的东西.但问题是堆栈跟踪太短了.我只有上面的列表.它根本不包括我自己的代码,因此有点难以猜测bug的位置.
以前有没有经历过这样的事情?任何想法如何开始解决它?
编辑:因为退出Swing应用程序System.exit(0)可能是"不干净",但我不想设置主框架,EXIT_ON_CLOSE因为我想确保应用程序退出时没有任何关键的事情,我添加了一个机制,以便它执行dispose()调用之前的主框架方法System.exit(0).所以它现在应该很干净,但偶尔也会发生异常.它发生在System.exit(0)被召唤之后; dispose()工作没有问题.也就是说,它必须来自一个关闭钩子:
mainFrame.dispose(); // No problem! After this returns, all visible GUI is gone.
// In fact, if there were no other threads around, the VM could terminate here.
System.exit(0); // Throws an InterruptedException from sun.java2d.Disposer.run
Run Code Online (Sandbox Code Playgroud)
我甚至尝试Window通过循环遍历Window.getWindows()数组显式处理所有s (它包含无主Dialog …
java concurrency multithreading java-2d interrupted-exception