Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: bring final NCE in sync with final CE

...

Code Block
bgColor#FFCCCC
public class Waiter {
  private Thread thread;
  private boolean flag;
  private final Object lock = new Object();

  public void doSomething() {
    thread = new Thread(new Runnable() {
      @Override public void run() {
        synchronized(lock) {
          while (!flag) {
            try {
              lock.wait();
              // ...
            } catch (InterruptedException e) {
              // Forward to handler
            }
          }
        }
      }
    });
    thread.start();
  }

  public boolean stop() {
    if (thread != null) {
      if (thread.getState() == Thread.State.WAITING) {
        flagsynchronized = true;
(lock) {
          synchronizedflag (lock) {= true;
          lock.notifyAll();
        }
        return true;
      }
    }
    return false;
  }
}

...