Package java.util.concurrent

Examples of java.util.concurrent.ExecutorService.submit()


        final CountDownLatch latch = new CountDownLatch(count);
        ExecutorService executor = Executors.newFixedThreadPool(count);
        try {
            for (int i = 0; i < count; i++) {
                final String label = String.format("thread-%d", i);
                futures.add(executor.submit(new Callable<Path>() {
                    @Override
                    public Path call() throws Exception {
                        LOG.info("Wait: resolve @" + label);
                        latch.countDown();
                        if (latch.await(5, TimeUnit.SECONDS) == false) {
View Full Code Here


        final ExecutorService service = Executors.newCachedThreadPool();
        final Runnable[] tasks = solver.createParallelTasks(3, 5000);
        final List<Future<?>> execOutput = new ArrayList<Future<?>>();
        // Run tasks.
        for (Runnable r : tasks) {
            execOutput.add(service.submit(r));
        }
        // Wait for completion (ignoring return value).
        try {
            for (Future<?> f : execOutput) {
                f.get();
View Full Code Here

          if (!options.runtimeShared()) {
              if (async) {
                  // AHC is broken when calling closeAsynchronously.
                  // https://github.com/AsyncHttpClient/async-http-client/issues/290
                  final ExecutorService e = Executors.newSingleThreadExecutor();
                  e.submit(new Runnable() {
                      @Override
                      public void run() {
                          options.runtime().close();
                          e.shutdown();
                      }
View Full Code Here

  public Future<?> start() {
    BatchCoordinator coordinator = createCoordinator();
    ExecutorService executor = Executors.newFixedThreadPool( 1, "batch coordinator" );
    try {
      Future<?> submit = executor.submit( coordinator );
      return submit;
    }
    finally {
      executor.shutdown();
    }
View Full Code Here

    ExecutorService executorService = Executors.newFixedThreadPool(50);

    for (int i = 0; i < EXECUTIONS; i++)
    {
      Runnable task = TASKS[RND.nextInt(TASKS.length)];
      executorService.submit(task);
    }
    LATCH.await();
    executorService.shutdown();
    DATA_STORE.destroy();
  }
View Full Code Here

      final Canceler canceler = new Canceler();
     
      // Save namespace
      fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
      try {
        Future<Void> saverFuture = pool.submit(new Callable<Void>() {
          @Override
          public Void call() throws Exception {
            image.saveNamespace(finalFsn, NameNodeFile.IMAGE, canceler);
            return null;
          }
View Full Code Here

        });

        // Wait until saveNamespace calls getGenerationStamp
        delayer.waitForCall();
        // then cancel the saveNamespace
        Future<Void> cancelFuture = pool.submit(new Callable<Void>() {
          @Override
          public Void call() throws Exception {
            canceler.cancel("cancelled");
            return null;
          }
View Full Code Here

            retryUpToMaximumTimeWithFixedSleep(10, 10, TimeUnit.SECONDS));
   
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Thread> futureThread = new AtomicReference<Thread>();
    ExecutorService exec = Executors.newSingleThreadExecutor();
    Future<Throwable> future = exec.submit(new Callable<Throwable>(){
      @Override
      public Throwable call() throws Exception {
        futureThread.set(Thread.currentThread());
        latch.countDown();
        try {
View Full Code Here

            for (TokenRange range : masterRangeNodes)
            {
                if (jobRange == null)
                {
                    // for each range, pick a live owner and ask it to compute bite-sized splits
                    splitfutures.add(executor.submit(new SplitCallable(range, conf)));
                }
                else
                {
                    Range<Token> dhtRange = new Range<Token>(partitioner.getTokenFactory().fromString(range.start_token),
                                                             partitioner.getTokenFactory().fromString(range.end_token),
View Full Code Here

                        for (Range<Token> intersection: dhtRange.intersectionWith(jobRange))
                        {
                            range.start_token = partitioner.getTokenFactory().toString(intersection.left);
                            range.end_token = partitioner.getTokenFactory().toString(intersection.right);
                            // for each range, pick a live owner and ask it to compute bite-sized splits
                            splitfutures.add(executor.submit(new SplitCallable(range, conf)));
                        }
                    }
                }
            }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.