org.zkoss.util
Class ScalableTimer

java.lang.Object
  extended by org.zkoss.util.ScalableTimer

public class ScalableTimer
extends java.lang.Object

A facility for threads to schedule tasks for future execution in a background thread. It has the same function as Timer, but it is scalable by use of a collection of Timer. Use ScalableTimer if you want to schedule a lot of tasks. However, it doesn't support repeated execution.

Since:
3.0.1
Author:
tomyeh

Constructor Summary
ScalableTimer(int cTimers, int threshold)
          Creates a scalable timer.
 
Method Summary
 void cancel()
          Terminates this timer, discarding any currently scheduled tasks.
 int getMaxTimerSize()
          Returns the maximal allowed number of timers (Timer) are used in this instance.
 int getThreshold()
          Returns the threshold, i.e., the allowed number of tasks to be scheduled for a timer, before starting a new timer.
 void schedule(ScalableTimerTask task, java.util.Date time)
          Schedules the specified task for execution at the specified time.
 void schedule(ScalableTimerTask task, long delay)
          Schedules the specified task for execution after the specified delay.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScalableTimer

public ScalableTimer(int cTimers,
                     int threshold)
Creates a scalable timer.

Note: no real timer (thread) is created until the first task being scheduled.

Parameters:
cTimers - the maximal allowed number of timers to use. 1 is assumed if nonpositive.
threshold - the threshold, i.e., the number of tasks allowed to be scheduled for a timer before creating additional timer. 1 is assumed if nonpositive. Note: if the number of scheduled task exceeds the capacity (getMaxTimerSize() * getThreshold()), the tasks are distributed evenly over all timers
Method Detail

getMaxTimerSize

public int getMaxTimerSize()
Returns the maximal allowed number of timers (Timer) are used in this instance.


getThreshold

public int getThreshold()
Returns the threshold, i.e., the allowed number of tasks to be scheduled for a timer, before starting a new timer.


cancel

public void cancel()
Terminates this timer, discarding any currently scheduled tasks. This method may be called repeatedly; the second and subsequent calls have no effect.


schedule

public void schedule(ScalableTimerTask task,
                     long delay)
Schedules the specified task for execution after the specified delay.

Parameters:
task - task to be scheduled.
delay - delay in milliseconds before task is to be executed.

schedule

public void schedule(ScalableTimerTask task,
                     java.util.Date time)
Schedules the specified task for execution at the specified time.

Parameters:
task - task to be scheduled.
time - time at which task is to be executed.


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo