Class Uninterruptibles
- java.lang.Object
-
- com.google.common.util.concurrent.Uninterruptibles
-
@GwtCompatible(emulated=true) public final class Uninterruptibles extends Object
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
- Author:
- Anthony Zana
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
awaitTerminationUninterruptibly(ExecutorService executor)
Invokesexecutor.
awaitTermination(long, TimeUnit)
uninterruptibly with no timeout.static boolean
awaitTerminationUninterruptibly(ExecutorService executor, long timeout, TimeUnit unit)
Invokesexecutor.
awaitTermination(long, TimeUnit)
uninterruptibly.static boolean
awaitTerminationUninterruptibly(ExecutorService executor, Duration timeout)
Invokesexecutor.
awaitTermination(long, TimeUnit)
uninterruptibly.static void
awaitUninterruptibly(CountDownLatch latch)
Invokeslatch.
await()
uninterruptibly.static boolean
awaitUninterruptibly(CountDownLatch latch, long timeout, TimeUnit unit)
Invokeslatch.
await(timeout, unit)
uninterruptibly.static boolean
awaitUninterruptibly(CountDownLatch latch, Duration timeout)
Invokeslatch.
await(timeout, unit)
uninterruptibly.static boolean
awaitUninterruptibly(Condition condition, long timeout, TimeUnit unit)
Invokescondition.
await(timeout, unit)
uninterruptibly.static boolean
awaitUninterruptibly(Condition condition, Duration timeout)
Invokescondition.
await(timeout, unit)
uninterruptibly.static <V extends @Nullable Object>
VgetUninterruptibly(Future<V> future)
Invokesfuture.
get()
uninterruptibly.static <V extends @Nullable Object>
VgetUninterruptibly(Future<V> future, long timeout, TimeUnit unit)
Invokesfuture.
get(timeout, unit)
uninterruptibly.static <V extends @Nullable Object>
VgetUninterruptibly(Future<V> future, Duration timeout)
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 void
joinUninterruptibly(Thread toJoin, Duration timeout)
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 void
sleepUninterruptibly(Duration sleepFor)
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, int permits, Duration timeout)
Invokessemaphore.
tryAcquire(permits, timeout, unit)
uninterruptibly.static boolean
tryAcquireUninterruptibly(Semaphore semaphore, long timeout, TimeUnit unit)
Invokessemaphore.
tryAcquire(1, timeout, unit)
uninterruptibly.static boolean
tryAcquireUninterruptibly(Semaphore semaphore, Duration timeout)
Invokessemaphore.
tryAcquire(1, timeout, unit)
uninterruptibly.static boolean
tryLockUninterruptibly(Lock lock, long timeout, TimeUnit unit)
Invokeslock.
tryLock(timeout, unit)
uninterruptibly.static boolean
tryLockUninterruptibly(Lock lock, Duration timeout)
Invokeslock.
tryLock(timeout, unit)
uninterruptibly.
-
-
-
Method Detail
-
awaitUninterruptibly
@GwtIncompatible public static void awaitUninterruptibly(CountDownLatch latch)
Invokeslatch.
await()
uninterruptibly.
-
awaitUninterruptibly
@CanIgnoreReturnValue @GwtIncompatible public static boolean awaitUninterruptibly(CountDownLatch latch, Duration timeout)
Invokeslatch.
await(timeout, unit)
uninterruptibly.- Since:
- 28.0
-
awaitUninterruptibly
@CanIgnoreReturnValue @GwtIncompatible public static boolean awaitUninterruptibly(CountDownLatch latch, long timeout, TimeUnit unit)
Invokeslatch.
await(timeout, unit)
uninterruptibly.
-
awaitUninterruptibly
@GwtIncompatible public static boolean awaitUninterruptibly(Condition condition, Duration timeout)
Invokescondition.
await(timeout, unit)
uninterruptibly.- Since:
- 28.0
-
awaitUninterruptibly
@GwtIncompatible public static boolean awaitUninterruptibly(Condition condition, long timeout, TimeUnit unit)
Invokescondition.
await(timeout, unit)
uninterruptibly.- Since:
- 23.6
-
joinUninterruptibly
@GwtIncompatible public static void joinUninterruptibly(Thread toJoin)
InvokestoJoin.
join()
uninterruptibly.
-
joinUninterruptibly
@GwtIncompatible public static void joinUninterruptibly(Thread toJoin, Duration timeout)
Invokesunit.
timedJoin(toJoin, timeout)
uninterruptibly.- Since:
- 28.0
-
joinUninterruptibly
@GwtIncompatible public static void joinUninterruptibly(Thread toJoin, long timeout, TimeUnit unit)
Invokesunit.
timedJoin(toJoin, timeout)
uninterruptibly.
-
getUninterruptibly
@CanIgnoreReturnValue public static <V extends @Nullable Object> V getUninterruptibly(Future<V> future) throws ExecutionException
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
@CanIgnoreReturnValue @GwtIncompatible public static <V extends @Nullable Object> V getUninterruptibly(Future<V> future, Duration timeout) 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- Since:
- 28.0
- To retrieve a result from a
-
getUninterruptibly
@CanIgnoreReturnValue @GwtIncompatible public static <V extends @Nullable Object> 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
-
takeUninterruptibly
@GwtIncompatible public static <E> E takeUninterruptibly(BlockingQueue<E> queue)
Invokesqueue.
take()
uninterruptibly.
-
putUninterruptibly
@GwtIncompatible public static <E> void putUninterruptibly(BlockingQueue<E> queue, E element)
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
@GwtIncompatible public static void sleepUninterruptibly(Duration sleepFor)
Invokesunit.
sleep(sleepFor)
uninterruptibly.- Since:
- 28.0
-
sleepUninterruptibly
@GwtIncompatible public static void sleepUninterruptibly(long sleepFor, TimeUnit unit)
Invokesunit.
sleep(sleepFor)
uninterruptibly.
-
tryAcquireUninterruptibly
@GwtIncompatible public static boolean tryAcquireUninterruptibly(Semaphore semaphore, Duration timeout)
Invokessemaphore.
tryAcquire(1, timeout, unit)
uninterruptibly.- Since:
- 28.0
-
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, Duration timeout)
Invokessemaphore.
tryAcquire(permits, timeout, unit)
uninterruptibly.- Since:
- 28.0
-
tryAcquireUninterruptibly
@GwtIncompatible public static boolean tryAcquireUninterruptibly(Semaphore semaphore, int permits, long timeout, TimeUnit unit)
Invokessemaphore.
tryAcquire(permits, timeout, unit)
uninterruptibly.- Since:
- 18.0
-
tryLockUninterruptibly
@GwtIncompatible public static boolean tryLockUninterruptibly(Lock lock, Duration timeout)
Invokeslock.
tryLock(timeout, unit)
uninterruptibly.- Since:
- 30.0
-
tryLockUninterruptibly
@GwtIncompatible public static boolean tryLockUninterruptibly(Lock lock, long timeout, TimeUnit unit)
Invokeslock.
tryLock(timeout, unit)
uninterruptibly.- Since:
- 30.0
-
awaitTerminationUninterruptibly
@GwtIncompatible public static void awaitTerminationUninterruptibly(ExecutorService executor)
Invokesexecutor.
awaitTermination(long, TimeUnit)
uninterruptibly with no timeout.- Since:
- 30.0
-
awaitTerminationUninterruptibly
@GwtIncompatible public static boolean awaitTerminationUninterruptibly(ExecutorService executor, Duration timeout)
Invokesexecutor.
awaitTermination(long, TimeUnit)
uninterruptibly.- Since:
- 30.0
-
awaitTerminationUninterruptibly
@GwtIncompatible public static boolean awaitTerminationUninterruptibly(ExecutorService executor, long timeout, TimeUnit unit)
Invokesexecutor.
awaitTermination(long, TimeUnit)
uninterruptibly.- Since:
- 30.0
-
-