Package com.j_spaces.kernel
Class ScheduledRunner
java.lang.Object
java.lang.Thread
com.gigaspaces.internal.utils.concurrent.GSThread
com.j_spaces.kernel.ScheduledRunner
- All Implemented Interfaces:
Runnable
ScheduledRunner is a single daemon thread that wakes up at fixed intervals, to run a single
Runnable task. Calling cancel() method will wake up and terminate this daemon
thread.
Much like Timer but without the overhead of a managed queue of
tasks.
Usage:
ScheduledRunner runner =
new ScheduledRunner( new YourRunnable(), "Runnable Name", 0 /delay/, 1000 /period/);
...
runner.reschedule(2000); //reschedule with a new period
...
runner.cancel(); //cancel - no longer needed
runner = null; //help gc
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionScheduledRunner(Runnable target, long delay, long period) Allocates a newScheduledRunnerobject.ScheduledRunner(Runnable target, String name, long delay, long period) Allocates a newScheduledRunnerobject. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels all subsequent executions of the Runnable target.final voidreschedule(long period) Reschedules this Runnable execution for a new specified duration immediately.voidrun()Runs the Runnable target'srunmethod after every sleep interval unlesscancelmethod was invoked, or if this thread was Interrupted.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
ScheduledRunner
Allocates a newScheduledRunnerobject. This constructor has the same effect asScheduledRunner(target,name)where name is the target's class name.- Parameters:
target- the object whoserunmethod is called.delay- delay in milliseconds before task is to be executed.period- time in milliseconds between successive Runnable target executions.- See Also:
-
ScheduledRunner
Allocates a newScheduledRunnerobject. This constructor has the same effect asScheduledRunner(target)where name is a chosen name for this Runnable target.- Parameters:
target- the object whoserunmethod is called.name- the chosen name for this Runnable target.period- time in milliseconds between successive Runnable target executions.- See Also:
-
-
Method Details
-
run
public void run()Runs the Runnable target'srunmethod after every sleep interval unlesscancelmethod was invoked, or if this thread was Interrupted. -
reschedule
public final void reschedule(long period) Reschedules this Runnable execution for a new specified duration immediately. Much like scheduling with a no delay for a renewal period. If the Runnable target is currently awake, it will fall asleep only after its execution. Otherwise, it will wakeup, run, and fall asleep for the new duration.- Parameters:
period- the new period for this Runnable target.
-
cancel
public void cancel()Cancels all subsequent executions of the Runnable target. If a target is currently running, it will end gracefully.
-