Future isDone - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Future isDone method.

This code example shows how to use the following methods:cancel, get, isCancelled, isDone
        AsyncBean bean = lookup(AsyncBean.class);
        final CountDownLatch latch = new CountDownLatch(1);
        final CountDownLatch latch2 = new CountDownLatch(1);
        final Future<String> future = bean.asyncCancelMethod(latch, latch2);
        latch.await(WAIT_TIME_S, TimeUnit.SECONDS);
        Assert.assertFalse(future.isDone()); // we are in async method
        Assert.assertFalse(future.isCancelled());
        boolean wasCanceled = future.cancel(true); // we are running - task can't be canceled
        if (wasCanceled) {
            Assert.assertTrue("isDone() was expected to return true after a call to cancel() with mayBeInterrupting = true, returned true", future.isDone());
            Assert.assertTrue("isCancelled() was expected to return true after a call to cancel() returned true", future.isCancelled());
        } 
        latch2.countDown();
        String result = future.get();
        Assert.assertFalse(wasCanceled); // this should be false because task was not cancelled
        Assert.assertEquals("false;true", result); // the bean knows that it was cancelled
    } 
    
    @Test 
    @RunAsClient 
8
CodeRank
This code example shows how to use the following methods:isDone
        return nodeFuture.isCancelled();
    } 
 
    @Override 
    public boolean isDone() { 
        return nodeFuture.isDone();
    } 
 
    @Override 
    public ServerDeploymentPlanResult get() throws InterruptedException, ExecutionException { 
        boolean cleanup = true;
        ModelNode node;
        try { 
            node = nodeFuture.get();
        } catch (InterruptedException ie) {
            cleanup = false;  // still may be in progress, so wait for finalize()
            throw ie;
        } finally { 
            if (cleanup) {
                plan.cleanup();
7
CodeRank
This code example shows how to use the following methods:get, isCancelled, isDone
 
	public void update() { 
		if (future == null)
			return; 
 
		if (!future.isDone())
			return; 
 
		try { 
 
			if (future.isCancelled()) {
				futureHandler.failed(null);
			} else { 
				futureHandler.done(future.get());
			} 
 
		} catch (InterruptedException e) {
			futureHandler.failed(e);
		} catch (ExecutionException e) {
			futureHandler.failed(e);
7
CodeRank
This code example shows how to use the following methods:isDone
        return this.future.isCancelled();
    } 
 
    @Override 
    public boolean isDone() { 
        return this.future.isDone();
    } 
 
    @Override 
    public void run() { 
        this.future.run();
    } 
 
    @Override 
    public int compareTo(ComparableRunnableFuture<T, C> future) {
        return this.comparable.compareTo(future.comparable);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:isDone
            return this.future.isCancelled();
        } 
 
        @Override 
        public boolean isDone() { 
            return this.future.isDone();
        } 
 
        @Override 
        public T get() throws InterruptedException, ExecutionException { 
            return this.future.get();
        } 
 
        @Override 
        public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
            return this.future.get(timeout, unit);
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:isDone
		return adaptee.isCancelled();
	} 
 
	@Override 
	public boolean isDone() { 
		return adaptee.isDone();
	} 
 
	@Override 
	public T get() throws InterruptedException, ExecutionException {
		return adaptInternal(adaptee.get());
	} 
 
	@Override 
	public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
		return adaptInternal(this.adaptee.get(timeout, unit));
	} 
 
	@SuppressWarnings("unchecked") 
	final T adaptInternal(S adapteeResult) throws ExecutionException {
6
CodeRank
This code example shows how to use the following methods:cancel, isDone
  synchronized void runAsynchronously() { 
    future = executor.submit(task);
  } 
 
  synchronized void cancelIfNotFinished() { 
    if (future != null && !future.isDone()) {
      future.cancel(true);
    } 
  } 
 
  static class TaskBuilder { 
    private final JProgressBar progressBar;
    private long periodInMs = 1000;
 
    TaskBuilder(@Nonnull JProgressBar progressBar) {
      this.progressBar = progressBar;
    } 
 
    @Nonnull 
    TaskBuilder after(long duration, @Nonnull TimeUnit timeUnit) {
6
CodeRank
This code example shows how to use the following methods:cancel, get, isCancelled, isDone
    serverSocket.close();
    Future<Socket> connectorTask = executor.submit(connector);
 
    // this connection attempt will always timeout 
    try { 
      connectorTask.get(SHORT_DELAY, TimeUnit.MILLISECONDS);
      fail(); 
    } catch(TimeoutException e) {
    } 
    Exception lastException = exceptionHandler.awaitConnectionFailed(DELAY);
    assertTrue(lastException instanceof ConnectException);
    assertFalse(connectorTask.isDone());
    connectorTask.cancel(true);
 
    //thread.join(4 * DELAY); 
    assertTrue(connectorTask.isCancelled());
  } 
 
  @Test(timeout = 5000)
  public void testConnectEventually() throws Exception {
    serverSocket.close();
7
CodeRank
This code example shows how to use the following methods:get, isDone
    protected void afterExecute(Runnable r, Throwable t) {
        super.afterExecute(r, t);
        if (r instanceof Future<?>) {
            Future<?> future = (Future<?>)r;
            try { 
                if (future.isDone()) {
                    future.get();
                } 
                future.get();
            } catch (InterruptedException e) { // Ignore
            } catch (CancellationException e) { // Ignore also
            } catch (ExecutionException e) {
                if (e.getCause() != null) {
                    fExceptions.add(e.getCause());
                } 
            } 
        } 
    } 
     
    public boolean exceptionsCaught() { 
6
CodeRank
This code example shows how to use the following methods:isDone
 
    @Override 
    public boolean isDone() { 
 
        if (innerFuture != null) {
            return innerFuture.isDone();
        } 
 
        isDone = true;
        return isDone;
    } 
 
    /** 
     * Invoked when a {@link Broadcaster} completed its broadcast operation. 
     */ 
    public BroadcasterFuture<E> done() { 
        isDone = true;
 
        if (latch != null) {
            latch.countDown();
6
CodeRank
isDone Method Overview
Returns true if this task completed.
See Code Examples for other Java 8 Future Methods: