get Generic Future With Exception - Java java.lang

Java examples for java.lang:Throwable

Description

get Generic Future With Exception

Demo Code


//package com.java2s;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class Main {
    public static <V> Future<V> getGenericFutureWithException(
            final V returnValue, final Throwable error) {
        return new Future<V>() {

            @Override// ww w .ja  v  a 2s  . c om
            public boolean cancel(boolean arg0) {
                return false;
            }

            @Override
            public V get() throws InterruptedException, ExecutionException {
                return null;
            }

            @Override
            public V get(long arg0, TimeUnit arg1)
                    throws InterruptedException, ExecutionException,
                    TimeoutException {
                throw new ExecutionException("TEST", error);
            }

            @Override
            public boolean isCancelled() {
                return false;
            }

            @Override
            public boolean isDone() {
                return false;
            }

        };
    }
}

Related Tutorials