freemarker.template.cache
Class UpdateTimer

java.lang.Object
  extended by freemarker.template.cache.UpdateTimer
All Implemented Interfaces:
java.lang.Runnable

public final class UpdateTimer
extends java.lang.Object
implements java.lang.Runnable

A timer for objects that implement Updateable. Creates a new thread, in which it periodically calls the Updateable's update() method.

Uses techniques from the document "Why Are Thread.stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnExit Deprecated?", from the Java API documentation.

Version:
$Id: UpdateTimer.java 1140 2013-04-14 12:01:41Z run2000 $

Constructor Summary
UpdateTimer(Updateable target, long delay)
          Constructs the timer with the update target and update interval.
 
Method Summary
 void run()
          Waits for the given period, then calls update(), if required.
 void startTiming(int niceness)
          Begins periodic automatic updates of the target.
 void stopTiming()
          Stops (immediately) automatically updating the target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UpdateTimer

public UpdateTimer(Updateable target,
                   long delay)
Constructs the timer with the update target and update interval.

Parameters:
target - the object to be updated.
delay - the number of milliseconds between updates.
Method Detail

startTiming

public void startTiming(int niceness)
Begins periodic automatic updates of the target. Since it can't be determined if an existing thread is Runnable or not, create and start a new thread

Parameters:
niceness - How much to decrease the priority of the timer thread by. The value is applied against the default priority of the new thread. The value may be negative, to indicate that the thread should have a greater priority than the default.

stopTiming

public void stopTiming()
Stops (immediately) automatically updating the target.


run

public void run()
Waits for the given period, then calls update(), if required. If someone decides to kill this thread, exit immediately.

Specified by:
run in interface java.lang.Runnable