tyrex.util
public final class BackgroundThread extends Thread
The thread waits for n number of milliseconds before running the runnable. The wait-run execution occurs in an infinite loop. If the runnable is garbage collected then the thread exits its loop and stops running.
For best results the runnable should not have an embedded loop. Obviously if the runnable has an infinite loop then this thread never ends by itself.
Constructor Summary | |
---|---|
BackgroundThread(Runnable runnable, long wait)
Create the BackgroundThread.
| |
BackgroundThread(Runnable runnable, long wait, String name)
Create the BackgroundThread.
| |
BackgroundThread(Runnable runnable, long wait, ThreadGroup threadGroup)
Create the BackgroundThread.
| |
BackgroundThread(Runnable runnable, long wait, ThreadGroup threadGroup, String name)
Create the BackgroundThread.
|
Method Summary | |
---|---|
boolean | getExitOnInterrupt()
Return true if the background thread exits when
it is interrupted.
|
long | getWait()
Return the time in milliseconds to wait before
the runnable is run.
|
void | run()
Run the runnable.
|
void | setExitOnInterrupt(boolean exitOnInterrupt)
Tell the background thread to exit or not, when
it is interrupted.
|
void | setWait(long wait)
Set the time in milliseconds to wait before the
the runnable is run.
|
Parameters: runnable the runnable to run wait the time to wait before the runnable is run.
Parameters: runnable the runnable to run wait the time to wait before the runnable is run. name the name of the Thread. Cannot be null.
Parameters: runnable the runnable to run wait the time to wait before the runnable is run. threadGroup the thread group of the new thread. Can br null.
Parameters: runnable the runnable to run wait the time to wait before the runnable is run. threadGroup the thread group of the new thread. Can br null. name the name of the Thread. Cannot be null.
Returns: true if the background thread exits when it is interrupted.
Returns: the wait time in milliseconds
If the runnable has been garbage collected the thread ends.
The thread sleeps the prescribed number of seconds before running the runnable. The wait-run execution occurs in an infinite loop
Parameters: exitOnInterrupt True if the background thread exits when it is interrupted
Parameters: wait the wait time in milliseconds. Must be greater than 0.