|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.util.Semaphore
This is a simple object to use as a semaphore. It handles exceptions.
Semaphore semaphore = new Semaphore;
if (noMoreToDo) semaphore.pause(); // only returns on a start() from another thread
// or from a thread.run(), process once a second or if asked to...
while (true)
{
processWork();
if (semaphore.pause( 1000))
Log.message( "Process paused for 1 second");
else
Log.message( "Process resumed on command in less than 1 second");
}
semaphone.pause(); // only continue on a resume - otherwise wait forever.
// and from another thread
if (workToDo) semaphore.resume();
If you don't need a special semaphore object, use Application.pause() and resume()
Application| Constructor Summary | |
Semaphore()
|
|
| Method Summary | |
void |
clear()
Clear any outstanding resumes rather than queue them up. |
void |
disable()
Neither pause nor resume will actually do anything. |
boolean |
pause()
Pause the running thread. |
boolean |
pause(int timeout)
Pause the running thread. |
void |
reenable()
Neither pause nor resume will actually do anything. |
void |
resume()
resume a thread that has been paused by a call on this object. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Semaphore()
| Method Detail |
public boolean pause()
public boolean pause(int timeout)
timeout - maximum milliseconds to remain locked.
public void resume()
public void clear()
public void disable()
public void reenable()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||