Package org.dellroad.stuff.java
Class ThreadParkingLot
java.lang.Object
org.dellroad.stuff.java.ThreadParkingLot
A place for threads to be parked and unparked.
- Since:
- 1.0.102
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet all of the threads parked on this instance.boolean
Determine if the given thread is currently parked on this instance.boolean
park
(long timeout) Park the current thread on this instance.boolean
Unpark a thread.
-
Constructor Details
-
ThreadParkingLot
public ThreadParkingLot()
-
-
Method Details
-
park
Park the current thread on this instance. Execution will halt untilunpark()
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
- iftimeout
is negativeInterruptedException
- if the current thread is interrupted
-
unpark
Unpark a thread.- Parameters:
thread
- the thread to unpark- Returns:
true
ifthread
was successfully unparked,false
ifthread
is not parked on this instance
-
isParked
Determine if the given thread is currently parked on this instance. Obviously, things can change so this only gives an answer at the point in time invoked.- Parameters:
thread
- the thread in question- Returns:
true
ifthread
is currently parked on this instance,false
otherwise
-
getParkedThreads
Get all of the threads parked on this instance. Obviously, things can change so this only gives an snapshot at the point in time invoked.- Returns:
- an unmodifiable
Set
containing a snapshot of all threads currently parked on this instance
-