Class ThreadParkingLot

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

public class ThreadParkingLot extends Object
A place for threads to be parked and unparked.
Since:
1.0.102
  • Constructor Details

    • ThreadParkingLot

      public ThreadParkingLot()
  • Method Details

    • 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. Obviously, things can change so this only gives an answer at the point in time invoked.
      Parameters:
      thread - the thread in question
      Returns:
      true if thread is currently parked on this instance, false otherwise
    • getParkedThreads

      public Set<Thread> 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