jMobileCore toolkit

com.jmobilecore.thread
Class AdvThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.jmobilecore.thread.AdvThread
All Implemented Interfaces:
java.lang.Runnable

public class AdvThread
extends java.lang.Thread

This class implements scheduling mechanism for repeatable task execution You can specify frequency of execution and delay before first start. Also you can temporaryly stop and resume task execution or manually run the specified task

Author:
Greg Gridin

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  int delay
          The delay (in milliseconds) before first execution of current task
protected  boolean forcedRun
          Indicates if current task is forces to run
protected  int frequency
          The frequency (in milliseconds) of repeatable task execution
protected  boolean isActive
          Indicates if current thread is in active phase
protected  boolean reset
          Indicates if the frequency was reset
 java.lang.Runnable task
          The task for current threas
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AdvThread(java.lang.Runnable task)
          Creates a new AdvThread instance for specified task.
AdvThread(java.lang.Runnable task, int frequency)
          Creates a new AdvThread instance for specified task and specifies frequency for repeatable execution.
 
Method Summary
protected  void destructor()
          Default destructor.
 void run()
          Overrides standard run method of Thread class This methods works as scheduler for Runnable task execution
 boolean runOnce()
          Manual execution of task

If task is running then it will continue to run, when completed no other executions will happen Next task launch is not affected unless task execution is not completed at the time of scheduled launch At this case next task launch is skipped

 boolean setFrequency(int frequency)
          Set frequency for automatic execution of thread
 boolean setFrequency(int frequency, int delay)
          Set frequency for automatic execution of thread
 boolean terminate()
          Terminates thread processing

If task is running then it will continue to run, when completed no other executions will happen if task is scheduled for execution, it will be cancelled

 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

delay

protected volatile int delay
The delay (in milliseconds) before first execution of current task


forcedRun

protected volatile boolean forcedRun
Indicates if current task is forces to run

See Also:
runOnce()

frequency

protected volatile int frequency
The frequency (in milliseconds) of repeatable task execution

See Also:
task

isActive

protected volatile boolean isActive
Indicates if current thread is in active phase


reset

protected volatile boolean reset
Indicates if the frequency was reset

See Also:
setFrequency(int frequency), setFrequency(int frequency, int delay)

task

public java.lang.Runnable task
The task for current threas

Constructor Detail

AdvThread

public AdvThread(java.lang.Runnable task)
Creates a new AdvThread instance for specified task.

Parameters:
task - The Runnable object containing task implementation. Task can be scheduled for repeatable or single tame execution later

AdvThread

public AdvThread(java.lang.Runnable task,
                 int frequency)
Creates a new AdvThread instance for specified task and specifies frequency for repeatable execution.

Parameters:
task - The Runnable object containing task implementation.
frequency - The frequency in milliseconds for repetable task execution Frequency should be non-negative integer, ignored otherwise If frequency is zero then automatic execution is deisabled, task could be excecuted by runOnce method only
Method Detail

destructor

protected void destructor()
Default destructor. Helps VM to perform garbage collection


run

public void run()
Overrides standard run method of Thread class This methods works as scheduler for Runnable task execution

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
task

runOnce

public boolean runOnce()
Manual execution of task

If task is running then it will continue to run, when completed no other executions will happen Next task launch is not affected unless task execution is not completed at the time of scheduled launch At this case next task launch is skipped


setFrequency

public boolean setFrequency(int frequency)
Set frequency for automatic execution of thread

Parameters:
frequency - The frequency in milliseconds for repeatable task execution If frequency is zero then automatic execution is deisabled, task could be excecuted by runOnce method only First execution of task will happen after frequency delay

setFrequency

public boolean setFrequency(int frequency,
                            int delay)
Set frequency for automatic execution of thread

Parameters:
frequency - The frequency in milliseconds for repeatable task execution If frequency is zero then automatic execution is deisabled, task could be excecuted by runOnce method only First execution of task will happen after frequency delay
delay - The delay in milliseconds of first task execution

terminate

public boolean terminate()
Terminates thread processing

If task is running then it will continue to run, when completed no other executions will happen if task is scheduled for execution, it will be cancelled


jMobileCore toolkit