EventQueue inconsistent ID's

大憨熊 提交于 2019-12-05 13:44:06

That AWT Event Dispatch Thread may be shut down when it's no longer needed (this page describes both the spectification and the behaviour of the actual implementation in JDK 7).

This seems to happen here: You use the system EventQueue to handle one event. Then nothing needs it any more (no AWT/Swing components, ...). After some time it is shut down.

Then, when you use the EventQueue again another thread is started to take over that role.

So what happens here is that your Runnable.run() methods do get executed on two distinct threads. Both threads are "the AWT Event Dispatch Thread", just at different times in the JVMs life-cycle.

Maybe special casing this by using EventQueue.isDispatchThread() would be a possible solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!