简体   繁体   中英

what does this statement mean

unlike SwingUtilities.invokeAndWait(), the event thread is permitted to call SwingUtilities.invokeLater() . I cannot understand this clearly.

Please help me in this.

Another thread (not the main Swing event thread) can call invokeAndWait to wait for the Swing event thread to be ready to run some action. However, the Swing event thread cannot wait for itself. So it calls invokeLater to put the action in a queue for later execution.

不是Java开发人员,我认为如果在事件线程上执行invokAndWait ,它将有效地阻止自己。

Source

The invokeAndWait() method looks similar, but it has three important semantic differences. First, the invokeLater() method runs asynchronously at some time in the future. You don't know when it will actually run. On the other hand, the invokeAndWait() method is synchronous: it does not return until its target has completed execution. As a rule of thumb, then, you should use the invokeAndWait() method to read the value of Swing components or to ensure that something is displayed on the screen before you continue program execution. Otherwise, you can use the invokeLater() method.

The second difference is that the invokeAndWait() method cannot itself be called from the event-dispatching thread. The thread running the invokeAndWait() method must wait for the event-dispatching thread to execute some code. No thread, including the event-dispatching thread, can wait for itself to do something else. Consequently, if you execute the invokeAndWait() method from the event-dispatching thread, it throws a java.lang.Error. That causes the event-dispatching thread to exit (unless you've taken the unusual step of catching Error objects in your code); in turn, your entire program becomes disabled.

The third difference is that the invokeAndWait() method can throw an InterruptedException if the thread is interrupted before the event-dispatching thread runs the target, or an InvocationTargetException if the Runnable object throws a runtime exception or error.

-IvarD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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