Multiple Event Dispatch Threads

∥☆過路亽.° 提交于 2020-01-02 03:43:06

问题


I am new to Java Swing and my question is related to Event Queues and Dispatch threads.

I read that it is possible to have multiple event queues , each per AppContext instance. Similarly does it mean each AppContext Event queue has its own event dispatch thread.


回答1:


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.




回答2:


1) basically you only needed to know if your code will be done on EDT (all changes must be done on EDT),

2) if you have any doubts, it is possible to test

if (EventQueue.isDispatchThread()) {

or (that's same and returns true if is on EDT)

if (SwingUtilities.isEventDispatchThread()) {

more here or here

3) all output from Background tasks must be wrapped into invokeLater(), basic stuff about Concurency in Swing



来源:https://stackoverflow.com/questions/7323306/multiple-event-dispatch-threads

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