org.dellroad.stuff.java
Class ThreadParkingLot

java.lang.Object
  extended by org.dellroad.stuff.java.ThreadParkingLot

public class ThreadParkingLot
extends Object

A place for threads to be parked and unparked.

Since:
1.0.102

Constructor Summary
ThreadParkingLot()
           
 
Method Summary
 boolean isParked(Thread thread)
          Determine if the given thread is currently parked on this instance.
 boolean park(long timeout)
          Park the current thread on this instance.
 boolean unpark(Thread thread)
          Unpark a thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadParkingLot

public ThreadParkingLot()
Method Detail

park

public boolean park(long timeout)
             throws InterruptedException
Park the current thread on this instance. Execution will halt until unpark() is invoked by some other thread with the current thread as the parameter, the given non-zero timeout expires, or the current thread is interrupted.

Parameters:
timeout - maximum time to stay parked, or zero to park indefinitely
Returns:
true if the thread was unparked by another thread, false if the timeout expired
Throws:
IllegalArgumentException - if timeout is negative
InterruptedException - if the current thread is interrupted

unpark

public boolean unpark(Thread thread)
Unpark a thread.

Parameters:
thread - the thread to unpark
Returns:
true if thread was successfully unparked, false if thread is not parked on this instance

isParked

public boolean isParked(Thread thread)
Determine if the given thread is currently parked on this instance.

Parameters:
thread - the thread in question
Returns:
true if thread is currently parked on this instance, false otherwise