Swing 工具包和多线程 [英] Swing Toolkit and multithreading

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

问题描述

据说Swing 工具包不是多线程安全的?

这句话是什么意思?

推荐答案

检查此链接:http://www.jguru.com/faq/view.jsp?EID=131370

所以为了简化实现Swing 库他们选择它不是线程安全.论点是大多数与 GUI 相关的工作都发生了在来自 GUI 的回调中发生在单个 GUI 线程上无论如何.授予 - 长期运行用户将不得不做更多的任务工作,如果他/她想做多线程活动...

So to simplify the implementation of Swing library they chose it to be not thread safe. The argument being that most of the GUI related work happens in the callbacks from the GUI which happen on the single GUI thread anyways. Granted - for long running tasks the user will have to do more work if he/she wants to do multithreaded activity...

特别是为 jfc 提供的链接.

Specially the link given for the jfc.

还有这个链接:http://www.it.uu.se/edu/course/homepage/devgui/vt03/out/ThreadsAndSwing.pdf

Swing 组件完成后显示在屏幕上,他们应该只能由事件处理线程.这事件处理线程(或只是事件线程)由自动启动当应用程序有一个 Java VM 时图形界面.事件线程调用诸如paint()之类的方法组件,actionPerformed() 上ActionListener,以及所有其他事件处理方法

After Swing components have been displayed on the screen, they should only be operated on by the event-handling thread. The event-handling thread (or just event thread) is started automatically by the Java VM when an application has a graphical interface. The event thread calls methods like paint() on Component, actionPerformed() on ActionListener, and all of the other event-handling methods

<小时>添加

检查我提供的第二个链接,特别是以下部分:GUI 设置中对工作线程的需求(还有一个示例可以解释它).在此引用以供参考:

Check the second link I have given, specially the section: The Need for Worker Threads in a GUI Setting (also there is an example for explaining it). Quoting here for reference:

事件线程起着关键作用在带有图形的应用程序中界面.将要执行的代码由事件处理线程应该是相对简短且无阻塞.如果事件处理线程被阻塞在一段代码中一段时间​​,没有可以处理其他事件!

The event thread plays a critical role in an application with a graphical interface. Code that will be executed by the event-handling thread should be relatively brief and nonblocking. If the event-handling thread is blocked in a section of code for a while, no other events can be processed!

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

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