简体   繁体   English

多事件调度线程

[英]Multiple Event Dispatch Threads

I am new to Java Swing and my question is related to Event Queues and Dispatch threads. 我是Java Swing的新手,我的问题与Event Queues和Dispatch threads有关。

I read that it is possible to have multiple event queues , each per AppContext instance. 我读到每个AppContext实例可以有多个事件队列。 Similarly does it mean each AppContext Event queue has its own event dispatch thread. 同样,这意味着每个AppContext事件队列都有自己的事件派发线程。

It is only possible to have one event dispatch thread as far as I'm aware. 据我所知,只能有一个事件派发线程。

Apparently AppContext is not meant to be used by developers , although I'm not really familiar with it. 显然,开发人员并不打算使用AppContext ,尽管我并不熟悉它。

1) basically you only needed to know if your code will be done on EDT (all changes must be done on EDT), 1)基本上你只需要知道你的代码是否会在EDT上完成(所有的更改都必须在EDT上完成),

2) if you have any doubts, it is possible to test 2)如果您有任何疑问,可以进行测试

if (EventQueue.isDispatchThread()) {

or (that's same and returns true if is on EDT) 或(如果在EDT上,则相同并返回true)

if (SwingUtilities.isEventDispatchThread()) {

more here or here 更多这里这里

3) all output from Background tasks must be wrapped into invokeLater() , basic stuff about Concurency in Swing 3)后台任务的所有输出必须包装到invokeLater() ,这是关于Swing中Concurency的基本内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM