Hyperic HQ Plugin API v. 4.4.0.2

org.hyperic.hq.application
Class Scheduler

java.lang.Object
  extended by org.hyperic.hq.application.Scheduler
All Implemented Interfaces:
ShutdownCallback

public class Scheduler
extends java.lang.Object
implements ShutdownCallback

A scheduler that internally uses a thread pool to permit concurrent execution of scheduled tasks. This scheduler is preferable to a Timer when the execution of one task may block long enough to delay execution of other tasks.


Field Summary
static long NO_INITIAL_DELAY
          Specify no initial delay when scheduling a task.
 
Constructor Summary
Scheduler(int poolSize)
          Creates a scheduler.
 
Method Summary
 void purgeTasks()
          Tries to remove from the work queue all Future tasks that have been cancelled.
 java.util.concurrent.ScheduledFuture scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period)
          Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.
 java.util.concurrent.ScheduledFuture scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long delay)
          Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.
 void shutdown()
          Shut down the scheduler in an orderly manner, allowing any currently executing tasks to complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_INITIAL_DELAY

public static final long NO_INITIAL_DELAY
Specify no initial delay when scheduling a task.

See Also:
Constant Field Values
Constructor Detail

Scheduler

public Scheduler(int poolSize)
Creates a scheduler.

Parameters:
poolSize - The thread pool size.
Throws:
java.lang.IllegalArgumentException - if the pool size is less than or equal to zero.
Method Detail

scheduleAtFixedRate

public java.util.concurrent.ScheduledFuture scheduleAtFixedRate(java.lang.Runnable task,
                                                                long initialDelay,
                                                                long period)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.

Parameters:
task - The task to execute.
initialDelay - The initial delay (in msec) before the first execution.
period - The period (in msec) between successive executions.
Returns:
A ScheduledFuture that may be used to cancel task execution.

scheduleWithFixedDelay

public java.util.concurrent.ScheduledFuture scheduleWithFixedDelay(java.lang.Runnable task,
                                                                   long initialDelay,
                                                                   long delay)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor.

Parameters:
task - The task to execute.
initialDelay - The initial delay (in msec) before the first execution.
delay - The delay (in msec) between termination of one execution and commencement of the next.
Returns:
A ScheduledFuture that may be used to cancel task execution.

purgeTasks

public void purgeTasks()
Tries to remove from the work queue all Future tasks that have been cancelled. This method can be useful as a storage reclamation operation, that has no other impact on functionality. Cancelled tasks are never executed, but may accumulate in work queues until worker threads can actively remove them. Invoking this method instead tries to remove them now. However, this method may fail to remove tasks in the presence of interference by other threads.


shutdown

public void shutdown()
Shut down the scheduler in an orderly manner, allowing any currently executing tasks to complete.

Specified by:
shutdown in interface ShutdownCallback

Hyperic HQ Plugin API v. 4.4.0.2

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.