public class Gate extends Object
Modifier and Type | Field and Description |
---|---|
boolean |
multipleEntry
If this is true then a thread can call hold()/grab() on a gate
multiple times - defaults to true.
|
String |
name |
Modifier and Type | Method and Description |
---|---|
boolean |
amOwner()
Return if the current thread is the owner of the gate.
|
Thread |
getOwner()
Return the owner of the gate.
|
boolean |
grab()
This tries to get ownership of the gate, but will not wait
if it cannot get ownership immediately.
|
void |
handoff(Thread other)
Hand off ownership of this gate to another Thread.
|
void |
leave()
Temporarily leave the Gate, to re-enter it again later.
|
void |
lock()
Attempt to acquire ownership of the Gate, waiting indefinitely.
|
boolean |
lock(TimeOut t)
Attempt to acquire ownership of the Gate, waiting for a specific length of time.
|
boolean |
reEnter()
Re-enter the Gate having left with the leave() call.
|
boolean |
release()
Release the gate.
|
void |
synchronize()
This attempts to hold the gate, waiting an indefinite time to do so.
|
void |
unlock()
Release the gate.
|
public boolean multipleEntry
public String name
public Gate()
public Gate(String name)
public void synchronize()
public boolean grab()
public boolean lock(TimeOut t) throws InterruptedException
t
- The length of time to wait for.InterruptedException
- If the Thread was interrupted.public void lock() throws InterruptedException
InterruptedException
- If the Thread was interrupted while waiting for the gate.public Thread getOwner()
public boolean amOwner()
public final boolean release()
public void unlock() throws IllegalThreadStateException
IllegalThreadStateException
public void leave() throws IllegalThreadStateException
IllegalThreadStateException
public boolean reEnter()
public void handoff(Thread other) throws IllegalThreadStateException
other
- the other Thread to hand off to.IllegalThreadStateException
- if the current thread does not hold the gate.