ch.aplu.util
Class HiResAlarmTimer

java.lang.Object
  extended by ch.aplu.util.BaseAlarmTimer
      extended by ch.aplu.util.HiResAlarmTimer

public class HiResAlarmTimer
extends BaseAlarmTimer

Alarm timer with high resolution. (Resolution normally better than 1 microseconds.) The timer's precision is not garanteed because of multitasking/multithreading of operating system and Java. The timer starts at the given preset time, runs backwards and stops when it reaches zero.

(When using timer events by registering a TimerListener, the AlarmTimer restarts automatically.)

(All timer manipulation methods call yield() of the current thread unless disabled by special constructor.)


Constructor Summary
HiResAlarmTimer(long alarmTime)
          Construct a alarm timer instance with better than 1 microsecond resolution on most systems and set its preset time in microseconds (us).
HiResAlarmTimer(long alarmTime, boolean autostart)
          Same as HiResAlarmTimer(alarmTime), but the timer starts immediately if autostart is true.
HiResAlarmTimer(long alarmTime, boolean autostart, boolean yield)
          Same as HiResAlarmTimer(alarmTime, autostart), but most methods calls Thread.yield() automatically, if yield is true.
 
Method Summary
 
Methods inherited from class ch.aplu.util.BaseAlarmTimer
addTimerListener, getTime, isRunning, resume, start, start, stop, stopEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HiResAlarmTimer

public HiResAlarmTimer(long alarmTime)
Construct a alarm timer instance with better than 1 microsecond resolution on most systems and set its preset time in microseconds (us). The timer must be started by calling start(). It runs backward and stops when it reaches zero.


HiResAlarmTimer

public HiResAlarmTimer(long alarmTime,
                       boolean autostart)
Same as HiResAlarmTimer(alarmTime), but the timer starts immediately if autostart is true.


HiResAlarmTimer

public HiResAlarmTimer(long alarmTime,
                       boolean autostart,
                       boolean yield)
Same as HiResAlarmTimer(alarmTime, autostart), but most methods calls Thread.yield() automatically, if yield is true. This may give a much better time response when using loops with an empty body like

while ( timer.isRunning() ) {}.