org.apache.jackrabbit.util
Class Timer

java.lang.Object
  extended by org.apache.jackrabbit.util.Timer

public class Timer
extends Object

Timer wraps the standard Java Timer class and implements a guaranteed shutdown of the background thread running in the Timer instance after a certain IDLE_TIME.


Nested Class Summary
static class Timer.Task
          Extends the TimerTask with callback hooks to this Timer implementation.
 
Constructor Summary
Timer(boolean isDeamon)
          Creates a new Timer instance.
 
Method Summary
 void cancel()
          Terminates this timer, discarding any currently scheduled tasks.
 void schedule(Timer.Task task, long delay, long period)
          Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Timer

public Timer(boolean isDeamon)
Creates a new Timer instance.

Parameters:
isDeamon - if true the background thread wil run as deamon.
Method Detail

schedule

public void schedule(Timer.Task task,
                     long delay,
                     long period)
Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay. Subsequent executions take place at approximately regular intervals separated by the specified period.

Parameters:
task - task to be scheduled.
delay - delay in milliseconds before task is to be executed.
period - time in milliseconds between successive task executions.
Throws:
IllegalArgumentException - if delay is negative, or delay + System.currentTimeMillis() is negative.
IllegalStateException - if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.
See Also:
Timer.schedule(java.util.TimerTask, long, long)

cancel

public void cancel()
Terminates this timer, discarding any currently scheduled tasks. Does not interfere with a currently executing task (if it exists). Once a timer has been terminated, its execution thread terminates gracefully, and no more tasks may be scheduled on it.

Note that calling this method from within the run method of a timer task that was invoked by this timer absolutely guarantees that the ongoing task execution is the last task execution that will ever be performed by this timer.

This method may be called repeatedly; the second and subsequent calls have no effect.



Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.