Example usage for java.util.concurrent Future isDone

List of usage examples for java.util.concurrent Future isDone

Introduction

In this page you can find the example usage for java.util.concurrent Future isDone.

Prototype

boolean isDone();

Source Link

Document

Returns true if this task completed.

Usage

From source file:com.netflix.genie.core.services.impl.JobStateServiceImpl.java

/**
 * {@inheritDoc}//ww  w.  j  a  v  a  2 s  .co  m
 */
@Override
public void done(final String jobId) throws GenieException {
    this.handle(jobId, () -> {
        final JobInfo jobInfo = jobs.get(jobId);
        final Future<?> task = jobInfo.getRunningTask();
        if (task != null && !task.isDone()) {
            if (task.cancel(true)) {
                log.debug("Successfully cancelled job task for job {}", jobId);
            } else {
                log.error("Unable to cancel job task for job {}", jobId);
                this.unableToCancel.increment();
            }
        }
        jobs.remove(jobId);
        return null;
    });
}

From source file:edu.byu.softwareDistribution.web.controller.shopper.MyInvoicesController.java

private void waitForAll(final Collection<Future> futures) {
    for (final Future f : futures) {
        try {/*  ww  w.  java  2  s  .co m*/
            f.isDone();
        } catch (Throwable ignore) {
        }
    }
}

From source file:com.auditbucket.registration.service.TagService.java

public Collection<TagInputBean> processTags(final Company company, final List<TagInputBean> tagInputs) {
    //schemaDao.ensureUniqueIndexes(company, tagInputs);
    Future<Collection<TagInputBean>> future = makeTags(company, tagInputs);
    while (!future.isDone())
        Thread.yield();/*from   w  w  w. j a  v  a2 s .  c  o m*/
    try {
        return future.get();
    } catch (InterruptedException | ExecutionException e) {
        logger.error("Processing tags", e);
    }
    return null;
}

From source file:org.apache.olingo.fit.v3.AsyncTestITCase.java

@Test
public void createMediaEntity() throws Exception {
    URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Car");

    final String TO_BE_UPDATED = "async buffered stream sample";
    final InputStream input = IOUtils.toInputStream(TO_BE_UPDATED);

    final ODataMediaEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory()
            .getMediaEntityCreateRequest(builder.build(), input);

    final MediaEntityCreateStreamManager<ODataEntity> streamManager = createReq.payloadManager();
    final Future<ODataMediaEntityCreateResponse<ODataEntity>> futureCreateRes = streamManager
            .getAsyncResponse();/*from   w  ww  . j a va2  s . c  om*/

    while (!futureCreateRes.isDone()) {
        Thread.sleep(1000L);
    }

    final ODataMediaEntityCreateResponse<ODataEntity> createRes = futureCreateRes.get();
    assertEquals(201, createRes.getStatusCode());

    final ODataEntity created = createRes.getBody();
    assertNotNull(created);
    assertEquals(2, created.getProperties().size());

    final int id = "VIN".equals(created.getProperties().get(0).getName())
            ? created.getProperties().get(0).getPrimitiveValue().toCastValue(Integer.class)
            : created.getProperties().get(1).getPrimitiveValue().toCastValue(Integer.class);

    builder = client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Car").appendKeySegment(id);

    final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory()
            .getMediaEntityRequest(builder.build());

    final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
    assertEquals(200, retrieveRes.getStatusCode());
    assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody()));
}

From source file:cn.ctyun.amazonaws.services.s3.transfer.internal.UploadMonitor.java

/**
 * Polls for a result from a multipart upload and either returns it if
 * complete, or reschedules to poll again later if not.
 *//* w ww  .j a  va2s.  c o m*/
private UploadResult poll() throws InterruptedException {
    for (Future<PartETag> f : futures) {
        if (!f.isDone()) {
            reschedule();
            return null;
        }
    }

    for (Future<PartETag> f : futures) {
        if (f.isCancelled()) {
            throw new CancellationException();
        }
    }

    return completeMultipartUpload();
}

From source file:com.brienwheeler.lib.concurrent.ExecutorsTest.java

@Test
public void testNewSingleThreadExecutorInvokeAll() throws InterruptedException, ExecutionException {
    NamedThreadFactory threadFactory = new NamedThreadFactory(THREAD_FACTORY_NAME);
    ExecutorService executor = Executors.newSingleThreadExecutor(threadFactory);

    IntCallable one = new IntCallable(1);
    IntCallable two = new IntCallable(2);
    ArrayList<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
    tasks.add(one);//from   w  w  w  . jav a2  s. c o  m
    tasks.add(two);

    List<Future<Integer>> results = executor.invokeAll(tasks);
    Assert.assertEquals(2, results.size());
    Iterator<Future<Integer>> it = results.iterator();
    Future<Integer> oneResult = it.next();
    Future<Integer> twoResult = it.next();
    Assert.assertTrue(oneResult.isDone());
    Assert.assertEquals(1, oneResult.get().intValue());
    Assert.assertEquals(2, twoResult.get().intValue());

    results = executor.invokeAll(tasks, 10, TimeUnit.MILLISECONDS);
    Assert.assertEquals(2, results.size());
    it = results.iterator();
    oneResult = it.next();
    twoResult = it.next();
    Assert.assertTrue(oneResult.isDone());
    Assert.assertEquals(1, oneResult.get().intValue());
    Assert.assertEquals(2, twoResult.get().intValue());

    executor.shutdown();
}

From source file:com.jimmyrengga.sample.asynctask.Runner.java

private void runAsync() throws Exception {
    long start = System.currentTimeMillis();

    Future<Page> page1 = sampleService.findPageAsync("GoPivotal");
    Future<Page> page2 = sampleService.findPageAsync("CloudFoundry");
    Future<Page> page3 = sampleService.findPageAsync("SpringFramework");

    while (!(page1.isDone() && page2.isDone() && page3.isDone())) {
        Thread.sleep(10); //millisecond pause between each check
    }//from w  ww. j  av  a2s  .  c  om

    // Print results, including elapsed time
    logger.info("Elapsed time: " + (System.currentTimeMillis() - start));
    logger.info(page1.get().toString());
    logger.info(page2.get().toString());
    logger.info(page3.get().toString());
}

From source file:com.company.project.service.TaskSchedulerService.java

@Scheduled(fixedRate = 60000)
public void schedulerFixedRate() {
    System.out.println("schedulerFixedRate. Current time is :: " + new Date());

    // spring managed thread
    TaskExample taskExample = new TaskExample();
    taskExample.setName("Thread 1");
    taskExecutor.execute(taskExample);//from  w  ww .j  a v a  2 s  .  c om

    asyncMethod();

    taskExample = new TaskExample();
    taskExample.setName("Thread 2");
    taskExecutor.execute(taskExample);

    taskExample = new TaskExample();
    taskExample.setName("Thread 3");
    Future future = taskExecutor.submit(taskExample);
    System.out.println("Thread 3 future.isCancelled() :: " + future.isCancelled());
    System.out.println("Thread 3 future.isDone() :: " + future.isDone());
    while (!future.isDone()) {
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
        }
    }
    System.out.println("Thread 3 future.isDone() :: " + future.isDone()); // future.isDone() = true

    AsyncTask asyncTask = new AsyncTask();
    asyncTask.doAsyncTask();
}

From source file:com.ejisto.modules.executor.TaskManager.java

private void refreshTasksList() {
    if (!lock.tryLock()) {
        return;/*from w ww  . j a  v a  2  s .c  o  m*/
    }
    try {
        registry.entrySet().stream().filter(e -> {
            Future<?> future = e.getValue().getFuture();
            return future.isCancelled() || future.isDone();
        }).collect(toList()).forEach(e -> registry.remove(e.getKey(), e.getValue()));
    } finally {
        lock.unlock();
    }

}

From source file:eu.europa.ec.fisheries.uvms.plugins.inmarsat.twostage.RetriverBean.java

/**
 * @return returns DNIDs available for download 
 *//*from w w w  .  j  a v a  2 s .c  o  m*/
private List<String> getDownloadDnids() {
    List<String> downloadDnids = new ArrayList<>();
    List<String> dnidList = getDnids();
    for (String dnid : dnidList) {
        Future existingFuture = connectFutures.get(dnid);
        if (!downloadDnids.contains(dnid) && (existingFuture == null || existingFuture.isDone())) {
            downloadDnids.add(dnid);
        }
    }

    return downloadDnids;
}