Package blbutil

Class MultiThreadUtils

java.lang.Object
blbutil.MultiThreadUtils

public class MultiThreadUtils extends Object
Class Utilities contains miscellaneous static utility methods for multi-threaded programming.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Blocks the current thread until the specified CountDownLatch has counted down to 0.
    static <E> void
    Inserts the specified element at the tail of the specified blocking queue, waiting for space to become available if the queue is full.
    static <E> boolean
    putInBlockingQ(BlockingQueue<E> q, E e, long timeout, TimeUnit unit)
    Inserts the specified element at the tail of the specified blocking queue, waiting up to the specified time for space to become available if the queue is full.
    static void
    Shuts down and awaits termination of the specified ExecutorService.
    static <E> E
    Removes and returns the element at the head of the specified blocking queue, waiting if necessary for an element to become available.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • putInBlockingQ

      public static <E> void putInBlockingQ(BlockingQueue<E> q, E e)
      Inserts the specified element at the tail of the specified blocking queue, waiting for space to become available if the queue is full. The Java Virtual Machine is terminated if an InterruptedException is thrown while waiting for space to be come available in the queue.
      Type Parameters:
      E - the element type
      Parameters:
      q - a blocking queue
      e - the element to add
      Throws:
      NullPointerException - if q == null || e == null
    • putInBlockingQ

      public static <E> boolean putInBlockingQ(BlockingQueue<E> q, E e, long timeout, TimeUnit unit)
      Inserts the specified element at the tail of the specified blocking queue, waiting up to the specified time for space to become available if the queue is full. The Java Virtual Machine is terminated if an InterruptedException is thrown while waiting for space to be come available in the queue.
      Type Parameters:
      E - the element type
      Parameters:
      q - a blocking queue
      e - the element to add
      timeout - the number of time units to wait before giving up
      unit - the time unit
      Returns:
      true if element was added to the queue, and false otherwise
      Throws:
      NullPointerException - if q == null || e == null || unit == null
    • takeFromBlockingQ

      public static <E> E takeFromBlockingQ(BlockingQueue<E> q)
      Removes and returns the element at the head of the specified blocking queue, waiting if necessary for an element to become available. The Java Virtual Machine is terminated if an InterruptedException is thrown while waiting for space to be come available in the queue.
      Type Parameters:
      E - the element type
      Parameters:
      q - a blocking queue
      Returns:
      the element at the head of the queue
    • await

      public static void await(CountDownLatch latch)
      Blocks the current thread until the specified CountDownLatch has counted down to 0. The Java Virtual Machine is terminated if an InterruptedException is thrown while waiting for for the CountDownLatch to count down to 0.
      Parameters:
      latch - the count down latch
      Throws:
      NullPointerException - if latch == null
    • shutdownExecService

      public static void shutdownExecService(ExecutorService es)
      Shuts down and awaits termination of the specified ExecutorService. The Java Virtual Machine is terminated if an InterruptedException is thrown while awaiting termination of the executor service.
      Parameters:
      es - the executor service to be shut down
      Throws:
      NullPointerException - if es == null