Java examples for Thread:Thread Safe
Handling spurious thread wakeups
import java.awt.EventQueue; import java.awt.Toolkit; public class Main { public void main() { boolean someCondition = false; String someObject = null;//from w w w. j av a2 s . com synchronized (someObject) { Toolkit toolkit = Toolkit.getDefaultToolkit(); EventQueue eventQueue = toolkit.getSystemEventQueue(); while (someCondition && !eventQueue.isDispatchThread()) { try { wait(); } catch (InterruptedException e) { } } // Continue processing } } }