jmri.util
Class WaitHandler

java.lang.Object
  extended by jmri.util.WaitHandler

public class WaitHandler
extends Object

Common utility class for handling the "spurious wakeup from wait()" problem described in the Object.wait(long) JavaDocs Generally, when waiting for a notify() operation, you need to provide a test that a valid notify had happened due to e.g. a state change, etc.

  new WaitHandler(this, 120) {
      protected boolean wasSpurious() {
          return !(state == expectedNextState); 
      }
  };
By default, interrupting the thread leaves the wait early with the interrupted flag set. InterruptedException is not thrown. You can modify this behavior via the handleInterruptedException routine.

Author:
Bob Jacobsen Copyright 2010

Constructor Summary
WaitHandler(Object self)
          Wait forever, robustly handling "spurious wake"
WaitHandler(Object self, long interval)
          Wait for a specified interval, robustly handling "spurious wake"
 
Method Summary
protected  boolean wasSpurious()
          Method to determine if a wake was spurious or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaitHandler

public WaitHandler(Object self,
                   long interval)
Wait for a specified interval, robustly handling "spurious wake"

Parameters:
self - waiting Object
interval - in milliseconds

WaitHandler

public WaitHandler(Object self)
Wait forever, robustly handling "spurious wake"

Parameters:
self - waiting Object
Method Detail

wasSpurious

protected boolean wasSpurious()
Method to determine if a wake was spurious or not. By default, all wakes are considered not spurious and the full time may not elapse. Override to provide a test (returning true) when there's a way to tell that a wake was spurious and the wait() should continue.



Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads