Class Uninterruptibles
java.lang.Object
com.google.common.util.concurrent.Uninterruptibles
Utilities for treating interruptible operations as uninterruptible. In all cases, if a thread is
interrupted during such a call, the call continues to block until the result is available or the
timeout elapses, and only then re-interrupts the thread.
- Since:
- 10.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Invokeslatch.
await()
uninterruptibly.static boolean
awaitUninterruptibly
(CountDownLatch latch, long timeout, TimeUnit unit) Invokeslatch.
await(timeout, unit)
uninterruptibly.static <V> V
getUninterruptibly
(Future<V> future) Invokesfuture.
get()
uninterruptibly.static <V> V
getUninterruptibly
(Future<V> future, long timeout, TimeUnit unit) Invokesfuture.
get(timeout, unit)
uninterruptibly.static void
joinUninterruptibly
(Thread toJoin) InvokestoJoin.
join()
uninterruptibly.static void
joinUninterruptibly
(Thread toJoin, long timeout, TimeUnit unit) Invokesunit.
timedJoin(toJoin, timeout)
uninterruptibly.static <E> void
putUninterruptibly
(BlockingQueue<E> queue, E element) Invokesqueue.
put(element)
uninterruptibly.static void
sleepUninterruptibly
(long sleepFor, TimeUnit unit) Invokesunit.
sleep(sleepFor)
uninterruptibly.static <E> E
takeUninterruptibly
(BlockingQueue<E> queue) Invokesqueue.
take()
uninterruptibly.static boolean
tryAcquireUninterruptibly
(Semaphore semaphore, int permits, long timeout, TimeUnit unit) Invokessemaphore.
tryAcquire(permits, timeout, unit)
uninterruptibly.static boolean
tryAcquireUninterruptibly
(Semaphore semaphore, long timeout, TimeUnit unit) Invokessemaphore.
tryAcquire(1, timeout, unit)
uninterruptibly.
-
Method Details
-
awaitUninterruptibly
Invokeslatch.
await()
uninterruptibly. -
awaitUninterruptibly
@GwtIncompatible public static boolean awaitUninterruptibly(CountDownLatch latch, long timeout, TimeUnit unit) Invokeslatch.
await(timeout, unit)
uninterruptibly. -
joinUninterruptibly
InvokestoJoin.
join()
uninterruptibly. -
getUninterruptibly
Invokesfuture.
get()
uninterruptibly.Similar methods:
- To retrieve a result from a
Future
that is already done, useFutures.getDone
. - To treat
InterruptedException
uniformly with other exceptions, useFutures.getChecked
. - To get uninterruptibility and remove checked exceptions, use
Futures.getUnchecked(java.util.concurrent.Future<V>)
.
- Throws:
ExecutionException
- if the computation threw an exceptionCancellationException
- if the computation was cancelled
- To retrieve a result from a
-
getUninterruptibly
@GwtIncompatible public static <V> V getUninterruptibly(Future<V> future, long timeout, TimeUnit unit) throws ExecutionException, TimeoutException Invokesfuture.
get(timeout, unit)
uninterruptibly.Similar methods:
- To retrieve a result from a
Future
that is already done, useFutures.getDone
. - To treat
InterruptedException
uniformly with other exceptions, useFutures.getChecked
. - To get uninterruptibility and remove checked exceptions, use
Futures.getUnchecked(java.util.concurrent.Future<V>)
.
- Throws:
ExecutionException
- if the computation threw an exceptionCancellationException
- if the computation was cancelledTimeoutException
- if the wait timed out
- To retrieve a result from a
-
joinUninterruptibly
Invokesunit.
timedJoin(toJoin, timeout)
uninterruptibly. -
takeUninterruptibly
Invokesqueue.
take()
uninterruptibly. -
putUninterruptibly
Invokesqueue.
put(element)
uninterruptibly.- Throws:
ClassCastException
- if the class of the specified element prevents it from being added to the given queueIllegalArgumentException
- if some property of the specified element prevents it from being added to the given queue
-
sleepUninterruptibly
Invokesunit.
sleep(sleepFor)
uninterruptibly. -
tryAcquireUninterruptibly
@GwtIncompatible public static boolean tryAcquireUninterruptibly(Semaphore semaphore, long timeout, TimeUnit unit) Invokessemaphore.
tryAcquire(1, timeout, unit)
uninterruptibly.- Since:
- 18.0
-
tryAcquireUninterruptibly
@GwtIncompatible public static boolean tryAcquireUninterruptibly(Semaphore semaphore, int permits, long timeout, TimeUnit unit) Invokessemaphore.
tryAcquire(permits, timeout, unit)
uninterruptibly.- Since:
- 18.0
-