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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet all of the threads parked on this instance.booleanDetermine if the given thread is currently parked on this instance.booleanpark(long timeout) Park the current thread on this instance.booleanUnpark 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:
trueif the thread was unparked by another thread,falseif the timeout expired- Throws:
IllegalArgumentException- iftimeoutis negativeInterruptedException- if the current thread is interrupted
-
unpark
Unpark a thread.- Parameters:
thread- the thread to unpark- Returns:
trueifthreadwas successfully unparked,falseifthreadis 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:
trueifthreadis currently parked on this instance,falseotherwise
-
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
Setcontaining a snapshot of all threads currently parked on this instance
-