paulscode.sound
Class SimpleThread

java.lang.Object
  extended by java.lang.Thread
      extended by paulscode.sound.SimpleThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
CommandThread, StreamThread

public class SimpleThread
extends java.lang.Thread

The SimpleThread class is the template used to create all thread classes used by in the SoundSystem library. It provides methods for common actions like sleeping, killing, and checking liveness. NOTE: super.cleanup() must be called at the bottom of overriden cleanup() methods, and cleanup() must be called at the bottom of the run() method for all extended classes.

SoundSystem License:

You are free to use this library for any purpose, commercial or otherwise. You may modify this library or source code, and distribute it any way you like, provided the following conditions are met:
1) You may not falsely claim to be the author of this library or any unmodified portion of it.
2) You may not copyright this library or a modified version of it and then sue me for copyright infringement.
3) If you modify the source code, you must clearly document the changes made before redistributing the modified source code, so other users know it is not the original code.
4) You are not required to give me credit for this library in any derived work, but if you do, you must also mention my website: http://www.paulscode.com
5) I the author will not be responsible for any damages (physical, financial, or otherwise) caused by the use if this library or any part of it.
6) I the author do not guarantee, warrant, or make any representations, either expressed or implied, regarding the use of this library or any part of it.

Author: Paul Lamb
http://www.paulscode.com


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SimpleThread()
           
 
Method Summary
 boolean alive()
          Returns false when the cleanup() method has finished.
protected  void cleanup()
          Removes all references to instantiated objects, and changes the thread's state to "not alive".
protected  boolean dying()
          Returns true when the thread is supposed to shut down.
 void kill()
          Causes method dying() to return true, letting the thread know it needs to shut down.
 void restart()
          Calls the rerun() method on a seperate thread, which calls run() when the previous thread finishes.
 void run()
          Executes the thread's main loop.
protected  void snooze(long milliseconds)
          Sleeps for the specified number of milliseconds.
 
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, 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
 

Constructor Detail

SimpleThread

public SimpleThread()
Method Detail

cleanup

protected void cleanup()
Removes all references to instantiated objects, and changes the thread's state to "not alive". Method alive() returns false when this method has completed. NOTE: super.cleanup() must be called at the bottom of overriden cleanup() methods, and cleanup() must be called at the bottom of the run() method for all extended classes.


run

public void run()
Executes the thread's main loop. NOTES: Extended classes should check method dying() often to know when the user wants the thread to shut down. Method cleanup() must be called at the bottom of the run() method for all extended classes.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

restart

public void restart()
Calls the rerun() method on a seperate thread, which calls run() when the previous thread finishes.


alive

public boolean alive()
Returns false when the cleanup() method has finished. This method should be used to know when the thread has been safely shut down.

Returns:
True while the thread is alive.

kill

public void kill()
Causes method dying() to return true, letting the thread know it needs to shut down.


dying

protected boolean dying()
Returns true when the thread is supposed to shut down.

Returns:
True if the thread should die.

snooze

protected void snooze(long milliseconds)
Sleeps for the specified number of milliseconds.