Java Thread Future getUninterruptibly(Future future)

Here you can find the source of getUninterruptibly(Future future)

Description

get Uninterruptibly

License

Apache License

Declaration

public static <T> T getUninterruptibly(Future<T> future) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.concurrent.ExecutionException;

import java.util.concurrent.Future;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T, A extends Throwable, B extends Throwable, C extends Throwable, D extends Throwable> T getUninterruptibly(
            Future<T> future, Class<A> throwableA, Class<B> throwableB,
            Class<C> throwableC, Class<D> throwableD) throws A, B, C, D {
        while (true) {
            try {
                return future.get();
            } catch (InterruptedException e) {
                //retry
            } catch (ExecutionException ee) {
                if (throwableA.isInstance(ee.getCause())) {
                    throw (A) ee.getCause();
                }/* w ww  .  ja va 2  s  .c  om*/
                if (throwableB.isInstance(ee.getCause())) {
                    throw (B) ee.getCause();
                }
                if (throwableC.isInstance(ee.getCause())) {
                    throw (C) ee.getCause();
                }
                if (throwableD.isInstance(ee.getCause())) {
                    throw (D) ee.getCause();
                }
                throw new RuntimeException(ee.getCause());
            }
        }
    }

    public static <T, A extends Throwable, B extends Throwable, C extends Throwable> T getUninterruptibly(
            Future<T> future, Class<A> throwableA, Class<B> throwableB,
            Class<C> throwableC) throws A, B, C {
        return getUninterruptibly(future, throwableA, throwableB,
                throwableC, RuntimeException.class);
    }

    public static <T, A extends Throwable, B extends Throwable> T getUninterruptibly(
            Future<T> future, Class<A> throwableA, Class<B> throwableB)
            throws A, B {
        return getUninterruptibly(future, throwableA, throwableB,
                RuntimeException.class, RuntimeException.class);
    }

    public static <T, A extends Throwable> T getUninterruptibly(
            Future<T> future, Class<A> throwableA) throws A {
        return getUninterruptibly(future, throwableA,
                RuntimeException.class, RuntimeException.class,
                RuntimeException.class);
    }

    public static <T> T getUninterruptibly(Future<T> future) {
        return getUninterruptibly(future, RuntimeException.class,
                RuntimeException.class, RuntimeException.class,
                RuntimeException.class);
    }
}

Related

  1. getFuture(Future future, String message)
  2. getMinIn(Map> responses)
  3. getResults(Iterable> futures)
  4. getSilently(Future future)
  5. getSysExeNameList()
  6. invokeTask(String threadName, Callable callable)
  7. isSuccessful(CompletableFuture f)
  8. nanoTime()
  9. now(Collection> s)