net.spy.util
Class LoopingThread

java.lang.Object
  extended byjava.lang.Thread
      extended bynet.spy.SpyThread
          extended bynet.spy.util.LoopingThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ThreadPoolManager

public abstract class LoopingThread
extends SpyThread

A Thread that loops over a runLoop().


Field Summary
static int DEFAULT_MS_PER_LOOP
          Default number of milliseconds to spend on each loop.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected LoopingThread()
          Get an instance of LoopingThread.
protected LoopingThread(String name)
          Get a LoopingThread with a specified name.
protected LoopingThread(ThreadGroup tg, String name)
          Get a looping thread belonging to a specific group and having the specified name.
 
Method Summary
 int getMsPerLoop()
          Get the number of milliseconds to sleep during each loop.
protected  void performDelay()
          Method to pause between loops.
 void requestStop()
          Request the looping should end.
 void run()
          The run loop itself.
protected abstract  void runLoop()
          This is the stuff that should happen during each execution of the run loop.
 void setMsPerLoop(int msPerLoop)
          Set the number of milliseconds to sleep during each loop.
 
Methods inherited from class net.spy.SpyThread
getLogger
 
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

DEFAULT_MS_PER_LOOP

public static final int DEFAULT_MS_PER_LOOP
Default number of milliseconds to spend on each loop.

See Also:
Constant Field Values
Constructor Detail

LoopingThread

protected LoopingThread()
Get an instance of LoopingThread.


LoopingThread

protected LoopingThread(String name)
Get a LoopingThread with a specified name.


LoopingThread

protected LoopingThread(ThreadGroup tg,
                        String name)
Get a looping thread belonging to a specific group and having the specified name.

Method Detail

setMsPerLoop

public void setMsPerLoop(int msPerLoop)
Set the number of milliseconds to sleep during each loop. Default is 5000 (five seconds).

Parameters:
msPerLoop - number of milliseconds to delay between loops

getMsPerLoop

public int getMsPerLoop()
Get the number of milliseconds to sleep during each loop.

Returns:
the number of milliseconds to wait during a loop.

requestStop

public void requestStop()
Request the looping should end.


runLoop

protected abstract void runLoop()
This is the stuff that should happen during each execution of the run loop.


performDelay

protected void performDelay()
Method to pause between loops. This is implemented via wait() so a notify() will cause this object to awaken from its sleep.


run

public void run()
The run loop itself.