com.google.common.util.concurrent
Class Uninterruptibles

java.lang.Object
  extended by com.google.common.util.concurrent.Uninterruptibles

@Beta
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
static void awaitUninterruptibly(CountDownLatch latch)
          Invokes latch.await() uninterruptibly.
static boolean awaitUninterruptibly(CountDownLatch latch, long timeout, TimeUnit unit)
          Invokes latch.await(timeout, unit) uninterruptibly.
static
<V> V
getUninterruptibly(Future<V> future)
          Invokes future.get() uninterruptibly.
static
<V> V
getUninterruptibly(Future<V> future, long timeout, TimeUnit unit)
          Invokes future.get(timeout, unit) uninterruptibly.
static void joinUninterruptibly(Thread toJoin)
          Invokes toJoin.join() uninterruptibly.
static void joinUninterruptibly(Thread toJoin, long timeout, TimeUnit unit)
          Invokes unit.timedJoin(toJoin, timeout) uninterruptibly.
static
<E> void
putUninterruptibly(BlockingQueue<E> queue, E element)
          Invokes queue.put(element) uninterruptibly.
static void sleepUninterruptibly(long sleepFor, TimeUnit unit)
          Invokes unit.sleep(sleepFor) uninterruptibly.
static
<E> E
takeUninterruptibly(BlockingQueue<E> queue)
          Invokes queue.take() uninterruptibly.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

awaitUninterruptibly

public static void awaitUninterruptibly(CountDownLatch latch)
Invokes latch.await() uninterruptibly.


awaitUninterruptibly

public static boolean awaitUninterruptibly(CountDownLatch latch,
                                           long timeout,
                                           TimeUnit unit)
Invokes latch.await(timeout, unit) uninterruptibly.


joinUninterruptibly

public static void joinUninterruptibly(Thread toJoin)
Invokes toJoin.join() uninterruptibly.


getUninterruptibly

public static <V> V getUninterruptibly(Future<V> future)
                            throws ExecutionException
Invokes future.get() uninterruptibly. To get uninterruptibility and remove checked exceptions, see Futures.getUnchecked(java.util.concurrent.Future).

If instead, you wish to treat InterruptedException uniformly with other exceptions, see Futures.get or Futures.makeChecked(java.util.concurrent.Future, com.google.common.base.Function).

Throws:
ExecutionException

getUninterruptibly

public static <V> V getUninterruptibly(Future<V> future,
                                       long timeout,
                                       TimeUnit unit)
                            throws ExecutionException,
                                   TimeoutException
Invokes future.get(timeout, unit) uninterruptibly.

If instead, you wish to treat InterruptedException uniformly with other exceptions, see Futures.get or Futures.makeChecked(java.util.concurrent.Future, com.google.common.base.Function).

Throws:
ExecutionException
TimeoutException

joinUninterruptibly

public static void joinUninterruptibly(Thread toJoin,
                                       long timeout,
                                       TimeUnit unit)
Invokes unit.timedJoin(toJoin, timeout) uninterruptibly.


takeUninterruptibly

public static <E> E takeUninterruptibly(BlockingQueue<E> queue)
Invokes queue.take() uninterruptibly.


putUninterruptibly

public static <E> void putUninterruptibly(BlockingQueue<E> queue,
                                          E element)
Invokes queue.put(element) uninterruptibly.


sleepUninterruptibly

public static void sleepUninterruptibly(long sleepFor,
                                        TimeUnit unit)
Invokes unit.sleep(sleepFor) uninterruptibly.



Copyright © 2010-2011. All Rights Reserved.