org.jasen.thread
Class ControlledThread

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.jasen.thread.StoppableThread
          extended byorg.jasen.thread.ControlledThread
All Implemented Interfaces:
Runnable, Stoppable
Direct Known Subclasses:
JasenAutoUpdateNotifier

public abstract class ControlledThread
extends StoppableThread

A simple thread implementation which provides the capability to be stopped.

Author:
Jason Polites

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ControlledThread()
           
ControlledThread(Runnable target)
           
ControlledThread(Runnable target, String name)
           
ControlledThread(String name)
           
ControlledThread(ThreadGroup group, Runnable target)
           
ControlledThread(ThreadGroup group, Runnable target, String name)
           
ControlledThread(ThreadGroup group, Runnable target, String name, long stackSize)
           
ControlledThread(ThreadGroup group, String name)
           
 
Method Summary
 void finish()
          Stops the thread.
 long getSleepTime()
          Gets the sleep time for the thread.
abstract  void handleException(Exception e)
          Handles unrecoverable errors.
 boolean isProcessOnStart()
          Indicates whether the thread will process on startup.
 boolean isRunning()
          Returns true if the thread is currently running.
abstract  void process()
          Performs the primary thread processing.
 void run()
           
 void setProcessOnStart(boolean processOnStart)
          Flags the thread to execute a process on startup.
 void setSleepTime(long sleepTime)
          Sets the sleep time for the thread.
 void wake()
          Wakes up the sleeping thread
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ControlledThread

public ControlledThread()

ControlledThread

public ControlledThread(Runnable target)
Parameters:
target -

ControlledThread

public ControlledThread(String name)
Parameters:
name -

ControlledThread

public ControlledThread(ThreadGroup group,
                        Runnable target)
Parameters:
group -
target -

ControlledThread

public ControlledThread(Runnable target,
                        String name)
Parameters:
target -
name -

ControlledThread

public ControlledThread(ThreadGroup group,
                        String name)
Parameters:
group -
name -

ControlledThread

public ControlledThread(ThreadGroup group,
                        Runnable target,
                        String name)
Parameters:
group -
target -
name -

ControlledThread

public ControlledThread(ThreadGroup group,
                        Runnable target,
                        String name,
                        long stackSize)
Parameters:
group -
target -
name -
stackSize -
Method Detail

run

public void run()

wake

public void wake()
Wakes up the sleeping thread


finish

public void finish()
Stops the thread.
The thread will only stop AFTER the current processing cycle has completed


isProcessOnStart

public boolean isProcessOnStart()
Indicates whether the thread will process on startup.

Returns:
True if the thread processes on startup, false otherwise.

setProcessOnStart

public void setProcessOnStart(boolean processOnStart)
Flags the thread to execute a process on startup.

Parameters:
processOnStart - True if the thread should process on startup. If false, the thread automatically enters a wait state

getSleepTime

public long getSleepTime()
Gets the sleep time for the thread. This is the time between run cycles.

Returns:
The sleep time in milliseconds

setSleepTime

public void setSleepTime(long sleepTime)
Sets the sleep time for the thread. This is the time between run cycles.
Default is wait forever (0)

Parameters:
sleepTime -

isRunning

public boolean isRunning()
Returns true if the thread is currently running.

Returns:

process

public abstract void process()
                      throws JasenException
Performs the primary thread processing.

Throws:
JasenException

handleException

public abstract void handleException(Exception e)
Handles unrecoverable errors.

Parameters:
e -