Package blbutil
Class MultiThreadUtils
java.lang.Object
blbutil.MultiThreadUtils
Class
Utilities
contains miscellaneous static utility methods
for multi-threaded programming.-
Method Summary
Modifier and TypeMethodDescriptionstatic void
await
(CountDownLatch latch) Blocks the current thread until the specifiedCountDownLatch
has counted down to 0.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.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 specifiedExecutorService
.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.
-
Method Details
-
putInBlockingQ
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:
NullPointerException
- ifq == null || e == null
-
putInBlockingQ
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:
NullPointerException
- ifq == null || e == null || unit == null
-
takeFromBlockingQ
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
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:
NullPointerException
- iflatch == null
-
shutdownExecService
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:
NullPointerException
- ifes == null
-