Package blbutil
Class MultiThreadUtils
- java.lang.Object
-
- blbutil.MultiThreadUtils
-
public class MultiThreadUtils extends java.lang.Object
ClassUtilities
contains miscellaneous static utility methods for multi-threaded programming.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
await(java.util.concurrent.CountDownLatch latch)
Blocks the current thread until the specifiedCountDownLatch
has counted down to 0.static <E> void
putInBlockingQ(java.util.concurrent.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.static <E> boolean
putInBlockingQ(java.util.concurrent.BlockingQueue<E> q, E e, long timeout, java.util.concurrent.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
shutdownExecService(java.util.concurrent.ExecutorService es)
Shuts down and awaits termination of the specifiedExecutorService
.static <E> E
takeFromBlockingQ(java.util.concurrent.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.
-
-
-
Method Detail
-
putInBlockingQ
public static <E> void putInBlockingQ(java.util.concurrent.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 anInterruptedException
is thrown while waiting for space to be come available in the queue.- Type Parameters:
E
- the element type- Parameters:
q
- a blocking queuee
- the element to add- Throws:
java.lang.NullPointerException
- ifq == null || e == null
-
putInBlockingQ
public static <E> boolean putInBlockingQ(java.util.concurrent.BlockingQueue<E> q, E e, long timeout, java.util.concurrent.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 anInterruptedException
is thrown while waiting for space to be come available in the queue.- Type Parameters:
E
- the element type- Parameters:
q
- a blocking queuee
- the element to addtimeout
- the number of time units to wait before giving upunit
- the time unit- Returns:
true
if element was added to the queue, and false otherwise- Throws:
java.lang.NullPointerException
- ifq == null || e == null || unit == null
-
takeFromBlockingQ
public static <E> E takeFromBlockingQ(java.util.concurrent.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 anInterruptedException
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(java.util.concurrent.CountDownLatch latch)
Blocks the current thread until the specifiedCountDownLatch
has counted down to 0. The Java Virtual Machine is terminated if anInterruptedException
is thrown while waiting for for theCountDownLatch
to count down to 0.- Parameters:
latch
- the count down latch- Throws:
java.lang.NullPointerException
- iflatch == null
-
shutdownExecService
public static void shutdownExecService(java.util.concurrent.ExecutorService es)
Shuts down and awaits termination of the specifiedExecutorService
. The Java Virtual Machine is terminated if anInterruptedException
is thrown while awaiting termination of the executor service.- Parameters:
es
- the executor service to be shut down- Throws:
java.lang.NullPointerException
- ifes == null
-
-