|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--java.lang.Thread
|
+--orthotweezers.CancelThread
A CancelThread extends Thread and allows a mechanism to cleanly pause or cancel the thread. When the thread is created its state is ENABLED (not to be confused with the interrupted or alive state). If the pause() or cancel() method is called, the state is set to PAUSED or CANCELLED, respectively. A thread may call CancelThread.check() and if pause() has been called (by another thread), check() will loop until the other thread calls unpause() or cancel(). If cancelled, check() throws a CancelException.
| Field Summary | |
static int |
CANCELLED
|
static int |
ENABLED
|
static int |
PAUSE_REQUEST
|
static int |
PAUSED
|
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
CancelThread(java.lang.Runnable runnable)
Creates a new CancelThread as in Thread(Runnable target) |
|
| Method Summary | |
void |
cancel()
This sets the state to CANCELLED so that the next call to check() from the running thread will throw a CancelException, or if check() is looping in the PAUSED state then it will also throw a CancelException. |
static void |
check()
If this thread state is still ENABLED, simply return. |
boolean |
isPaused()
Return true if the state of this thread is PAUSED. |
void |
pause()
This sets the state to PAUSE_REQUEST so that the next call to check() from the running thread will convert the state to PAUSED and loop until unpause() or cancel() is called. |
void |
unpause()
If the state is PAUSED, this sets the state back to ENABLED so that the check() method in which the other thread is looping can exit and allow the thread to resume. |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, 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 |
public static int ENABLED
public static int PAUSE_REQUEST
public static int PAUSED
public static int CANCELLED
| Constructor Detail |
public CancelThread(java.lang.Runnable runnable)
| Method Detail |
public void cancel()
check()public void pause()
check(),
unpause(),
cancel()public void unpause()
check(),
pause()
public static void check()
throws CancelException
This is a static method and queries Thread.currentThread() to see if the current thread is an instanceof CancelThread. If not, it simply returns, but if it is, then it looks at the state as described.
CancelException - if this object is no longer enabledcancel(),
pause(),
unpause()public boolean isPaused()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||