Example usage for org.springframework.util.concurrent ListenableFutureTask ListenableFutureTask

List of usage examples for org.springframework.util.concurrent ListenableFutureTask ListenableFutureTask

Introduction

In this page you can find the example usage for org.springframework.util.concurrent ListenableFutureTask ListenableFutureTask.

Prototype

public ListenableFutureTask(Callable<T> callable) 

Source Link

Document

Create a new ListenableFutureTask that will, upon running, execute the given Callable .

Usage

From source file:com.pepaproch.gtswsdl.client.RateLimitTest.java

private synchronized void addTask(AtomicInteger cc, ScheduledExecutorService schelduler, RateLimit rate,
        Instant[] end) {/*from w  w w.  j  a  v  a2 s.c o m*/

    Callable<Integer> callable = (Callable<Integer>) () -> {

        return cc.get();
    };
    ListenableFutureTask request = new ListenableFutureTask(callable);

    schelduler.schedule(() -> {
        FutureTask<?> schelduledTask = request;
        if (!request.isCancelled() && !request.isDone()) {
            schelduledTask.run();
        }

    }, rate.consumeSlot(), TimeUnit.MILLISECONDS);

    request.addCallback(new ListenableFutureCallback<Integer>() {

        @Override
        public void onSuccess(Integer result) {
            cc.incrementAndGet();
            end[0] = Instant.now();
            System.out.println("FINISHEDLISTENBALE: " + result + end[0].toString());
        }

        @Override
        public void onFailure(Throwable ex) {
            System.out.println("FAILURE");
        }
    });

}