Handling spurious thread wakeups - Java Thread

Java examples for Thread:Thread Safe

Description

Handling spurious thread wakeups

Demo Code

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
    }
  }
}

Related Tutorials