laur.tools
Class AbortableThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--laur.tools.AbortableThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
MonitoredThread

public abstract class AbortableThread
extends java.lang.Thread

This abstract class offers a general mechanism for thread abortion.


Field Summary
protected  boolean bAbort
          This will be true if the user requested abort, false otherwise.
protected  boolean isRunning
          This will be true if the thread is running, false otherwise.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbortableThread()
           
 
Method Summary
 void abort()
          Requests the abortion of the thread.
protected  void checkAbort()
          This method should be called in subclasses at critical points to check whether the user requested that the execution be aborted.
protected abstract  void execute()
          This method should be overwritten by subclasses to perform the thread actions.
 void run()
          Runs thread.
protected  void terminationHook()
          Called before thread terminates execution.
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

bAbort

protected boolean bAbort
This will be true if the user requested abort, false otherwise.


isRunning

protected boolean isRunning
This will be true if the thread is running, false otherwise.

Constructor Detail

AbortableThread

public AbortableThread()
Method Detail

execute

protected abstract void execute()
This method should be overwritten by subclasses to perform the thread actions.


run

public void run()
Runs thread. The thread can be interrupted through a call to abort().

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
Throws:
java.lang.IllegalStateException - if the thread is still running

terminationHook

protected void terminationHook()
Called before thread terminates execution. By default does nothing, overwrite to provide specific behavior.


abort

public void abort()
Requests the abortion of the thread.


checkAbort

protected void checkAbort()
This method should be called in subclasses at critical points to check whether the user requested that the execution be aborted. If the user wants to abort, then this method throws an AbortThreadRequest exception. AbortableThread.run() catches this exception.