com.lti.utils.synchronization
Class CloseableThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.lti.utils.synchronization.CloseableThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
MessageDrivenThread, SimpleSocketInputStream

public abstract class CloseableThread
extends java.lang.Thread

A base class for threads which need to be gracefully closed, since Thread.stop() is deprecated. Subclass should check isClosing() in their main loop in run(), and call setClosed() when run() completes.

Author:
Ken Larson

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  SynchronizedBoolean closing
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CloseableThread()
           
CloseableThread(java.lang.String threadName)
           
CloseableThread(java.lang.ThreadGroup group, java.lang.String threadName)
          Deprecated.  
 
Method Summary
 void close()
           
 boolean isClosed()
           
protected  boolean isClosing()
          intended to be checked by thread in its main loop.
protected  void setClosed()
          to be called by the thread upon exit.
protected  void setClosing()
           
 void waitUntilClosed()
           
 
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, run, 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

closing

protected final SynchronizedBoolean closing
Constructor Detail

CloseableThread

public CloseableThread()

CloseableThread

public CloseableThread(java.lang.String threadName)

CloseableThread

public CloseableThread(java.lang.ThreadGroup group,
                       java.lang.String threadName)
Deprecated. 

Method Detail

close

public void close()

setClosing

protected void setClosing()

isClosed

public boolean isClosed()

waitUntilClosed

public void waitUntilClosed()
                     throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

isClosing

protected boolean isClosing()
intended to be checked by thread in its main loop. break out of the main loop if true.


setClosed

protected void setClosed()
to be called by the thread upon exit.