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

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

Introduction

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

Prototype

boolean isCancelled();

Source Link

Document

Returns true if this task was cancelled before it completed normally.

Usage

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

private synchronized void addTask(AtomicInteger cc, ScheduledExecutorService schelduler, RateLimit rate,
        Instant[] end) {//w w w .  j  a  va 2s.com

    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");
        }
    });

}