Class Uninterruptibles


  • @GwtCompatible(emulated=true)
    public final class Uninterruptibles
    extends java.lang.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​(java.util.concurrent.ExecutorService executor)
      Invokes executor.awaitTermination(long, TimeUnit) uninterruptibly with no timeout.
      static boolean awaitTerminationUninterruptibly​(java.util.concurrent.ExecutorService executor, long timeout, java.util.concurrent.TimeUnit unit)
      Invokes executor.awaitTermination(long, TimeUnit) uninterruptibly.
      static void awaitUninterruptibly​(java.util.concurrent.CountDownLatch latch)
      Invokes latch.await() uninterruptibly.
      static boolean awaitUninterruptibly​(java.util.concurrent.CountDownLatch latch, long timeout, java.util.concurrent.TimeUnit unit)
      Invokes latch.await(timeout, unit) uninterruptibly.
      static boolean awaitUninterruptibly​(java.util.concurrent.locks.Condition condition, long timeout, java.util.concurrent.TimeUnit unit)
      Invokes condition.await(timeout, unit) uninterruptibly.
      static <V extends @Nullable java.lang.Object>
      V
      getUninterruptibly​(java.util.concurrent.Future<V> future)
      Invokes future.get() uninterruptibly.
      static <V extends @Nullable java.lang.Object>
      V
      getUninterruptibly​(java.util.concurrent.Future<V> future, long timeout, java.util.concurrent.TimeUnit unit)
      Invokes future.get(timeout, unit) uninterruptibly.
      static void joinUninterruptibly​(java.lang.Thread toJoin)
      Invokes toJoin.join() uninterruptibly.
      static void joinUninterruptibly​(java.lang.Thread toJoin, long timeout, java.util.concurrent.TimeUnit unit)
      Invokes unit.timedJoin(toJoin, timeout) uninterruptibly.
      static <E> void putUninterruptibly​(java.util.concurrent.BlockingQueue<E> queue, E element)
      Invokes queue.put(element) uninterruptibly.
      static void sleepUninterruptibly​(long sleepFor, java.util.concurrent.TimeUnit unit)
      Invokes unit.sleep(sleepFor) uninterruptibly.
      static <E> E takeUninterruptibly​(java.util.concurrent.BlockingQueue<E> queue)
      Invokes queue.take() uninterruptibly.
      static boolean tryAcquireUninterruptibly​(java.util.concurrent.Semaphore semaphore, int permits, long timeout, java.util.concurrent.TimeUnit unit)
      Invokes semaphore.tryAcquire(permits, timeout, unit) uninterruptibly.
      static boolean tryAcquireUninterruptibly​(java.util.concurrent.Semaphore semaphore, long timeout, java.util.concurrent.TimeUnit unit)
      Invokes semaphore.tryAcquire(1, timeout, unit) uninterruptibly.
      static boolean tryLockUninterruptibly​(java.util.concurrent.locks.Lock lock, long timeout, java.util.concurrent.TimeUnit unit)
      Invokes lock.tryLock(timeout, unit) uninterruptibly.
      • Methods inherited from class java.lang.Object

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

      • awaitUninterruptibly

        @GwtIncompatible
        public static boolean awaitUninterruptibly​(java.util.concurrent.CountDownLatch latch,
                                                   long timeout,
                                                   java.util.concurrent.TimeUnit unit)
        Invokes latch.await(timeout, unit) uninterruptibly.
      • awaitUninterruptibly

        @GwtIncompatible
        public static boolean awaitUninterruptibly​(java.util.concurrent.locks.Condition condition,
                                                   long timeout,
                                                   java.util.concurrent.TimeUnit unit)
        Invokes condition.await(timeout, unit) uninterruptibly.
        Since:
        23.6
      • joinUninterruptibly

        @GwtIncompatible
        public static void joinUninterruptibly​(java.lang.Thread toJoin,
                                               long timeout,
                                               java.util.concurrent.TimeUnit unit)
        Invokes unit.timedJoin(toJoin, timeout) uninterruptibly.
      • getUninterruptibly

        @CanIgnoreReturnValue
        public static <V extends @Nullable java.lang.Object> V getUninterruptibly​(java.util.concurrent.Future<V> future)
                                                                           throws java.util.concurrent.ExecutionException
        Invokes future.get() uninterruptibly.

        Similar methods:

        Throws:
        java.util.concurrent.ExecutionException - if the computation threw an exception
        java.util.concurrent.CancellationException - if the computation was cancelled
      • getUninterruptibly

        @CanIgnoreReturnValue
        @GwtIncompatible
        public static <V extends @Nullable java.lang.Object> V getUninterruptibly​(java.util.concurrent.Future<V> future,
                                                                                  long timeout,
                                                                                  java.util.concurrent.TimeUnit unit)
                                                                           throws java.util.concurrent.ExecutionException,
                                                                                  java.util.concurrent.TimeoutException
        Invokes future.get(timeout, unit) uninterruptibly.

        Similar methods:

        Throws:
        java.util.concurrent.ExecutionException - if the computation threw an exception
        java.util.concurrent.CancellationException - if the computation was cancelled
        java.util.concurrent.TimeoutException - if the wait timed out
      • putUninterruptibly

        @GwtIncompatible
        public static <E> void putUninterruptibly​(java.util.concurrent.BlockingQueue<E> queue,
                                                  E element)
        Invokes queue.put(element) uninterruptibly.
        Throws:
        java.lang.ClassCastException - if the class of the specified element prevents it from being added to the given queue
        java.lang.IllegalArgumentException - if some property of the specified element prevents it from being added to the given queue
      • sleepUninterruptibly

        @GwtIncompatible
        public static void sleepUninterruptibly​(long sleepFor,
                                                java.util.concurrent.TimeUnit unit)
        Invokes unit.sleep(sleepFor) uninterruptibly.
      • tryAcquireUninterruptibly

        @GwtIncompatible
        public static boolean tryAcquireUninterruptibly​(java.util.concurrent.Semaphore semaphore,
                                                        long timeout,
                                                        java.util.concurrent.TimeUnit unit)
        Invokes semaphore.tryAcquire(1, timeout, unit) uninterruptibly.
        Since:
        18.0
      • tryAcquireUninterruptibly

        @GwtIncompatible
        public static boolean tryAcquireUninterruptibly​(java.util.concurrent.Semaphore semaphore,
                                                        int permits,
                                                        long timeout,
                                                        java.util.concurrent.TimeUnit unit)
        Invokes semaphore.tryAcquire(permits, timeout, unit) uninterruptibly.
        Since:
        18.0
      • tryLockUninterruptibly

        @GwtIncompatible
        public static boolean tryLockUninterruptibly​(java.util.concurrent.locks.Lock lock,
                                                     long timeout,
                                                     java.util.concurrent.TimeUnit unit)
        Invokes lock.tryLock(timeout, unit) uninterruptibly.
        Since:
        30.0
      • awaitTerminationUninterruptibly

        @GwtIncompatible
        public static void awaitTerminationUninterruptibly​(java.util.concurrent.ExecutorService executor)
        Invokes executor.awaitTermination(long, TimeUnit) uninterruptibly with no timeout.
        Since:
        30.0
      • awaitTerminationUninterruptibly

        @GwtIncompatible
        public static boolean awaitTerminationUninterruptibly​(java.util.concurrent.ExecutorService executor,
                                                              long timeout,
                                                              java.util.concurrent.TimeUnit unit)
        Invokes executor.awaitTermination(long, TimeUnit) uninterruptibly.
        Since:
        30.0