net.groboclown.util.thread.v1
Class LoopThread

java.lang.Object
  |
  +--net.groboclown.util.thread.v1.LoopThread
Direct Known Subclasses:
QueueThread

public class LoopThread
extends Object

For threads which loop endlessly (which is a common thing), this class implements the pause, start, and stop routines since JDK 1.2 deprecated theirs.

This class delegates the Thread object, so that this class doesn't have to emulate all those thread methods. In this way, a LoopThread should act just like a Thread.

Version:
Alpha 0.9.0
Author:
Matt Albrecht

Inner Class Summary
private  class LoopThread.LoopRunnable
          The runnable class - keep it private so no one can directly access it in a thread but us.
 
Field Summary
private  boolean isPaused
           
private  boolean isRunning
           
static long MILLI_IN_SECOND
           
private  Object pauseObject
           
private  Runnable runnable
           
private  long sleepTime
           
private  Thread thisThread
           
private  boolean tryPause
           
private  boolean tryStop
           
 
Constructor Summary
LoopThread()
          Used in case the implementing class needs to postpone initialization until after the LoopThread construction.
LoopThread(Runnable loop)
           
LoopThread(Runnable loop, String threadName)
           
LoopThread(Runnable loop, ThreadGroup group)
           
LoopThread(Runnable loop, ThreadGroup group, String threadName)
           
 
Method Summary
 int getPriority()
           
 int getSleepTime()
          Retrieves the sleep time in seconds.
 long getSleepTimeMillis()
          Retrieves the sleep time in milliseconds.
 ThreadGroup getThreadGroup()
           
 boolean isAlive()
           
 boolean isDaemon()
           
 boolean isPaused()
           
 boolean isRunning()
           
 void join()
           
 void resume()
           
 void setDaemon(boolean on)
           
 void setPriority(int priority)
           
 void setRunnable(Runnable run)
          Sets the runnable instance after construction.
 void setSleepTime(int seconds)
          Sets the sleep time in seconds.
 void setSleepTimeMillis(long millis)
          Sets the sleep time in milliseconds.
 void start()
           
 void stop()
           
 void suspend()
          A non-deprecated, nice-to-the-system, thread suspension method.
 String toString()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

MILLI_IN_SECOND

public static final long MILLI_IN_SECOND

tryPause

private boolean tryPause

tryStop

private boolean tryStop

isPaused

private boolean isPaused

isRunning

private boolean isRunning

pauseObject

private Object pauseObject

sleepTime

private long sleepTime

thisThread

private Thread thisThread

runnable

private Runnable runnable
Constructor Detail

LoopThread

public LoopThread()
Used in case the implementing class needs to postpone initialization until after the LoopThread construction.

LoopThread

public LoopThread(Runnable loop)

LoopThread

public LoopThread(Runnable loop,
                  String threadName)

LoopThread

public LoopThread(Runnable loop,
                  ThreadGroup group)

LoopThread

public LoopThread(Runnable loop,
                  ThreadGroup group,
                  String threadName)
Method Detail

getPriority

public int getPriority()
See Also:
Thread.getPriority()

setPriority

public void setPriority(int priority)
See Also:
Thread.setPriority( int )

getThreadGroup

public ThreadGroup getThreadGroup()
See Also:
Thread.getThreadGroup()

isAlive

public boolean isAlive()
See Also:
Thread.isAlive()

isDaemon

public boolean isDaemon()
See Also:
Thread.isDaemon()

setDaemon

public void setDaemon(boolean on)
See Also:
Thread.setDaemon( boolean )

join

public void join()
          throws InterruptedException
See Also:
Thread.join()

setRunnable

public void setRunnable(Runnable run)
Sets the runnable instance after construction. It cannot be changed once the thread is running.

start

public void start()
See Also:
Thread.start()

suspend

public void suspend()
A non-deprecated, nice-to-the-system, thread suspension method.
See Also:
Thread.suspend()

resume

public void resume()
See Also:
Thread.resume()

stop

public void stop()
See Also:
Thread.stop()

isPaused

public boolean isPaused()

isRunning

public boolean isRunning()

getSleepTime

public int getSleepTime()
Retrieves the sleep time in seconds.

setSleepTime

public void setSleepTime(int seconds)
Sets the sleep time in seconds.

setSleepTimeMillis

public void setSleepTimeMillis(long millis)
Sets the sleep time in milliseconds.

getSleepTimeMillis

public long getSleepTimeMillis()
Retrieves the sleep time in milliseconds.

toString

public String toString()
Overrides:
toString in class Object
See Also:
Thread.toString()


Written under the LGPL