tyrex.util

Class BackgroundThread

public final class BackgroundThread extends Thread

This thread allows a runnable to run continously until the runnable is garbage collected.

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.

Author: Riad Mohammed

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
booleangetExitOnInterrupt()
Return true if the background thread exits when it is interrupted.
longgetWait()
Return the time in milliseconds to wait before the runnable is run.
voidrun()
Run the runnable.
voidsetExitOnInterrupt(boolean exitOnInterrupt)
Tell the background thread to exit or not, when it is interrupted.
voidsetWait(long wait)
Set the time in milliseconds to wait before the the runnable is run.

Constructor Detail

BackgroundThread

public BackgroundThread(Runnable runnable, long wait)
Create the BackgroundThread.

Parameters: runnable the runnable to run wait the time to wait before the runnable is run.

BackgroundThread

public BackgroundThread(Runnable runnable, long wait, String name)
Create the BackgroundThread.

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.

BackgroundThread

public BackgroundThread(Runnable runnable, long wait, ThreadGroup threadGroup)
Create the BackgroundThread.

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.

BackgroundThread

public BackgroundThread(Runnable runnable, long wait, ThreadGroup threadGroup, String name)
Create the BackgroundThread.

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.

Method Detail

getExitOnInterrupt

public boolean getExitOnInterrupt()
Return true if the background thread exits when it is interrupted.

Returns: true if the background thread exits when it is interrupted.

getWait

public long getWait()
Return the time in milliseconds to wait before the runnable is run.

Returns: the wait time in milliseconds

run

public void run()
Run the runnable.

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

setExitOnInterrupt

public void setExitOnInterrupt(boolean exitOnInterrupt)
Tell the background thread to exit or not, when it is interrupted.

Parameters: exitOnInterrupt True if the background thread exits when it is interrupted

setWait

public void setWait(long wait)
Set the time in milliseconds to wait before the the runnable is run.

Parameters: wait the wait time in milliseconds. Must be greater than 0.

Original code is Copyright (c) 1999-2001, Intalio, Inc. All Rights Reserved. Contributions by MetaBoss team are Copyright (c) 2003-2005, Softaris Pty. Ltd. All Rights Reserved.