|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.phoenix_int.util.PHXBlocker
public class PHXBlocker
Class to simplify wait and notify calls. Can be used to block one thread until some other thread signals a continue.
Sample usage:
import com.phoenix_int.util.PHXBlocker;
//
public class PHXThingie
{
PHXBlocker _blocker;
public PHXThingie()
{
_blocker = new PHXBlocker(); //create the blocker.
//You must call setBlock(true) before block. You should
//do it in a place before it is ever possible(however remote)
//that some other thread calls unblock first. In this case,
//before the subthread is started.
_blocker.setBlock(true);
//
MyThread t = new MyThread();
t.start(); //make a new thread that will unblock.
//
System.out.println("hi");
_blocker.block(); //this is the crux!
System.out.println("there");
}
//
//Thread that just sits around for 10 secs and then unblocks.
private class MyThread extends Thread
{
public void run()
{
try
{
sleep(10000);
} catch(InterruptedException ie)
{}
_blocker.unblock();
}
}
}
| Field Summary | |
|---|---|
static java.lang.String |
rcsid
|
| Constructor Summary | |
|---|---|
PHXBlocker()
|
|
| Method Summary | |
|---|---|
void |
block()
Blocks until unblock() is invoked. |
boolean |
block(long timeout)
Blocks until unblock is invoked or timeout has been reached |
boolean |
getBlock()
|
void |
setBlock(boolean block)
Call setBlock() before block() and before there is any remote chance that any other thread will call unblock(). |
void |
unblock()
|
void |
unblockAll()
Same as unblock except designed for multiple waiters. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String rcsid
| Constructor Detail |
|---|
public PHXBlocker()
| Method Detail |
|---|
public void setBlock(boolean block)
public boolean getBlock()
public boolean block(long timeout)
timeout - Maximum time to wait in milliseconds. Set to 0 to wait
forever.
public void block()
public void unblock()
public void unblockAll()
block(),
then use unblockAll().
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||