Example usage for java.util.concurrent CancellationException getCause

List of usage examples for java.util.concurrent CancellationException getCause

Introduction

In this page you can find the example usage for java.util.concurrent CancellationException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.punksearch.util.RenewableMemoizer.java

public V compute(final A arg) throws InterruptedException {
    __log.debug("Compute: " + arg);
    while (true) {
        Future<V> f = cache.get(arg);
        if (f == null) {
            FutureTask<V> ft = makeFutureTask(arg);
            f = cache.putIfAbsent(arg, ft);
            if (f == null) {
                f = ft;//from ww w.  j  a v a  2 s.  co  m
                ft.run();
            }
        } else {
            assert timestamps.get(arg) != null; // once put to timestamps value is never removed from it
            if (timestamps.get(arg) + timeout < System.currentTimeMillis()) {
                __log.debug("Item expired, removing from cache: " + arg);
                cache.remove(arg, f);
                continue;
            }
        }
        try {
            return f.get();
        } catch (CancellationException e) {
            cache.remove(arg, f);
        } catch (ExecutionException e) {
            throw LaunderThrowable.launderThrowable(e.getCause());
        }
    }
}