多个Swing事件派发线程 [英] Multiple Swing event-dispatch threads

查看:158
本文介绍了多个Swing事件派发线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Swing中创建一个新的事件派发线程,但我无法在线找到任何参考资料,以了解如何执行此操作。我通过创建一个新线程并调用Application.run(...)在.NET中完成了这个。有没有人这样做过?是否可以在Swing中使用?

I would like to create a new event-dispatch thread in Swing, and I'm having trouble finding any references online for how to do this. I have done this in .NET by creating a new thread and calling Application.run(...). Has anyone done this? Is it possible in Swing?

我想这样做的原因是因为我正在编写一个Eclipse插件,我想弹出对话框不是IDE的模态,但它是我的UI逻辑的模态(阻塞)。我可以使用非模态对话框和回调来实现这一点,但这需要使我的代码多线程的开销。如果前者不可能,我会回复。

FYI the reason I am trying to do this is because I am writing an Eclipse plug-in, and I would like to pop up dialogs that are not modal to the IDE but that are modal (blocking) to my UI logic. I could accomplish this using non-modal dialogs and callbacks, but that requires the overhead of making my code multi-threaded. I'll revert to that if the former is not possible.

推荐答案

是的,这是可能的。我已经在Swing中完成了这样的多个EDT调度线程逻辑。然而,最终结果是它无法可靠地工作。

Yes, it's possible. I've have done such multiple EDT dispatch threads logic in Swing. However, net result was that it didn't work reliably.

(a)所有JVM都不能很好地处理多个EDT线程(图形渲染逻辑中的同步问题)本机代码等,IBM JVM失败了多个EDT线程,Sun JVM和Apple JVM确实有效)

(a) All JVMs don't work nicely with multiple EDT threads (synchronization problems in graphics rendering logic in native code and such, IBM JVM failed with multiple EDT threads, Sun JVM & Apple JVM did work)

(b)Swing渲染逻辑几乎没有导致随机渲染的错误将发生错误(例如, http://bugs.sun.com/bugdatabase/ view_bug.do?bug_id=6727829 )。

(b) Swing rendering logic has few bugs causing that random rendering errors will occur (for example, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6727829).

无论如何,这样做基本上需要建立两个AppContexts,每个AppContex都有自己的EDT线程。

Anyway, doing this requires basically establishing two AppContexts, which each have their own EDT thread.

这篇关于多个Swing事件派发线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆