|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.lang.Thread
com.partnersoft.gadgets.LoopingThread
public class LoopingThread
Takes care of the (surprisingly annoying) case of repeating a task at a regular interval. Handles the problems of stopping and starting the process, and of timing the sleeps so that it iterates at the specified interval (rather than sleeping a constant amount between runs). To use, either instantiate it with a Runnable object with a run() method that does what you want to do each time we loop, or alternately use an anonymous or subclass and override the runTask() method. Do not override run() on the LoopingThread; that method is what provides our looping behavior!
| 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 | |
|---|---|
LoopingThread()
|
|
LoopingThread(java.lang.String name)
|
|
LoopingThread(java.lang.String name,
int interval)
|
|
LoopingThread(java.lang.String name,
int interval,
java.lang.Runnable task)
|
|
LoopingThread(java.lang.String name,
java.lang.Runnable task)
|
|
| Method Summary | |
|---|---|
int |
getInterval()
Gets the loop interval in milliseconds. |
java.lang.Runnable |
getTask()
|
void |
pauseLooping()
|
void |
resumeLooping()
|
void |
run()
|
void |
runTask()
By default, this runs the runnable. |
void |
setInterval(int newInterval)
Sets the loop interval in milliseconds. |
void |
setTask(java.lang.Runnable newTask)
|
void |
stopRunning()
Tells the thread to quit looping. |
| 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 |
|---|
public LoopingThread()
public LoopingThread(java.lang.String name)
public LoopingThread(java.lang.String name,
java.lang.Runnable task)
public LoopingThread(java.lang.String name,
int interval)
public LoopingThread(java.lang.String name,
int interval,
java.lang.Runnable task)
| Method Detail |
|---|
public void pauseLooping()
public void resumeLooping()
public void run()
run in interface java.lang.Runnablerun in class java.lang.Thread
public void runTask()
throws java.lang.Exception
java.lang.Exceptionpublic void stopRunning()
public void setInterval(int newInterval)
public int getInterval()
public void setTask(java.lang.Runnable newTask)
public java.lang.Runnable getTask()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||