Event dispatching thread: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Add: title. Changed bare reference to CS1/2. | Use this bot. Report bugs. | Suggested by BrownHairedGirl | Linked from User:BrownHairedGirl/Articles_with_bare_links | #UCB_webform_linked 118/2146
m Fixing usages of Javadoc:SE
Line 44:
=== Requests from other threads ===
 
Other application threads can pass some code to be executed in the event dispatching thread by means of {{Javadoc:SE|javax/swing|SwingUtilities|module=java.desktop}} helper classes (or {{Javadoc:SE|java/awt|EventQueue|module=java.desktop}} if you are doing [[Abstract Window Toolkit|AWT]]). The submitted code must be wrapped with a {{Javadoc:SE|java/lang|Runnable}} object. Two methods of these classes allow:
* synchronous code execution ({{Javadoc:SE|member=invokeAndWait(Runnable)|javax/swing|SwingUtilities|invokeAndWait(java.lang.Runnable)|module=java.desktop}} or {{Javadoc:SE|member=invokeAndWait(Runnable)|java/awt|EventQueue|invokeAndWait(java.lang.Runnable)|module=java.desktop}})
* and asynchronous code execution ({{Javadoc:SE|member=invokeLater(Runnable)|javax/swing|SwingUtilities|invokeLater(java.lang.Runnable)|module=java.desktop}} or {{Javadoc:SE|member=invokeLater(Runnable)|java/awt|EventQueue|invokeLater(java.lang.Runnable)|module=java.desktop}})
from the event dispatching thread.
 
The method <code>invokeAndWait()</code> should never be called from the event dispatching thread&mdash;it will throw an [[Exception handling|exception]]. The method {{Javadoc:SE|javax/swing|SwingUtilities|isEventDispatchThread()|module=java.desktop}} or {{Javadoc:SE|java/awt|EventQueue|isDispatchThread()|module=java.desktop}} can be called to determine if the current thread is the event dispatching thread.
 
The code supplied by means of the <code>invokeLater</code> and <code>invokeAndWait</code> to the EDT must be as quick as possible to prevent freezing. They are normally intended to deliver the result of a lengthy computation to the GUI (user).
Line 136:
 
== External links ==
* {{Javadoc:SE|package=javax.swing|javax/swing|module=java.desktop}} (Swing API [[Javadoc]] documentation)
* {{Javadoc:SE|package=java.awt|java/awt|module=java.desktop}} (AWT API [[Javadoc]] documentation)
* {{Javadoc:SE-guide|swing|Swing API documentation}}
* [http://download.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html The Event-Dispatching Thread]