当前位置: 首页>>代码示例>>Java>>正文


Java ListeningExecutorService.awaitTermination方法代码示例

本文整理汇总了Java中com.google.common.util.concurrent.ListeningExecutorService.awaitTermination方法的典型用法代码示例。如果您正苦于以下问题:Java ListeningExecutorService.awaitTermination方法的具体用法?Java ListeningExecutorService.awaitTermination怎么用?Java ListeningExecutorService.awaitTermination使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.util.concurrent.ListeningExecutorService的用法示例。


在下文中一共展示了ListeningExecutorService.awaitTermination方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onFinish

import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
private void onFinish(SingularityExecutorTask task, Protos.TaskState taskState) {
  processKiller.cancelDestroyFuture(task.getTaskId());

  tasks.remove(task.getTaskId());
  processRunningTasks.remove(task.getTaskId());
  processBuildingTasks.remove(task.getTaskId());

  task.cleanup(taskState);

  ListeningExecutorService executorService = taskToShellCommandPool.remove(task.getTaskId());

  if (executorService != null) {
    executorService.shutdownNow();
    try {
      executorService.awaitTermination(5, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
      LOG.warn("Awaiting shutdown of shell executor service", e);
    }
  }

  logging.stopTaskLogger(task.getTaskId(), task.getLogbackLog());

  checkIdleExecutorShutdown(task.getDriver());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:25,代码来源:SingularityExecutorMonitor.java

示例2: testConcurrentFetchTasks

import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
@Test
public void testConcurrentFetchTasks() throws Exception {
  // Test for regression of AURORA-1625
  ListeningExecutorService executor =
      MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5));
  assertStoreContents();
  saveTasks(TASK_A, TASK_B, TASK_C, TASK_D);

  List<ListenableFuture<Integer>> futures = Lists.newArrayList();

  for (int i = 0; i < 100; i++) {
    futures.add(executor.submit(() -> Iterables.size(fetchTasks(Query.unscoped()))));
  }

  Future<List<Integer>> f = Futures.allAsList(futures);

  executor.shutdown();
  executor.awaitTermination(1, TimeUnit.MINUTES);

  assertEquals(Iterables.getOnlyElement(ImmutableSet.copyOf(f.get())), (Integer) 4);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:22,代码来源:AbstractTaskStoreTest.java

示例3: shutdown

import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
private void shutdown(@Nullable final ListeningExecutorService executorService) {
    if (executorService != null) {
        executorService.shutdown();
        try {
            // Wait a while for existing tasks to terminate
            if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
                executorService.shutdownNow(); // Cancel currently executing tasks
                // Wait a while for tasks to respond to being cancelled
                if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
                    log.warn("Thread pool for metacat refresh did not terminate");
                }
            }
        } catch (InterruptedException ie) {
            // (Re-)Cancel if current thread also interrupted
            executorService.shutdownNow();
            // Preserve interrupt status
            Thread.currentThread().interrupt();
        }
    }
}
 
开发者ID:Netflix,项目名称:metacat,代码行数:21,代码来源:ElasticSearchRefresh.java

示例4: processFastqs

import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
/**
 * Counts yield and q30 of fastqs in the fastqsPerSample multimap, using 1 thread per file.
 * The yield and q30 of the Undetermined sample will count towards the total yield and q30 of the flowcell.
 *
 * @param fastqsPerSample multimap of sampleName and fastqs to process
 * @param threadCount     number of maximum threads
 * @return FastqTracker with yield and q30 stats for the fastqs processed.
 */

@NotNull
static FastqTracker processFastqs(@NotNull final Multimap<String, File> fastqsPerSample, final int threadCount)
        throws InterruptedException {
    LOGGER.info("Using " + threadCount + " threads. Processing " + fastqsPerSample.size() + " fastQ files.");
    final FastqTrackerWrapper tracker = new FastqTrackerWrapper();
    final ListeningExecutorService threadPool = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadCount));

    for (final String sampleName : fastqsPerSample.keySet()) {
        final Collection<File> fastqs = fastqsPerSample.get(sampleName);
        for (final File fastq : fastqs) {
            final String laneName = getLaneName(fastq);
            final ListenableFuture<FastqData> futureResult = threadPool.submit(() -> processFile(fastq));
            addCallback(futureResult, (data) -> tracker.addDataFromSampleFile(sampleName, laneName, data),
                    (error) -> LOGGER.error("Failed to process file: " + fastq.getName(), error));
        }
    }
    threadPool.shutdown();
    threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    return tracker.tracker();
}
 
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:30,代码来源:FastqStats.java

示例5: transactionMarker

import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
@Override
public void transactionMarker() throws Exception {
    ListeningExecutorService executor =
            MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
    ListenableFuture<Void> future1 = executor.submit(new Callable<Void>() {
        @Override
        public Void call() throws InterruptedException {
            Thread.sleep(100);
            return null;
        }
    });
    future1.addListener(new Runnable() {
        @Override
        public void run() {
            new CreateTraceEntry().traceEntryMarker();
        }
    }, executor);
    Thread.sleep(200);
    executor.shutdown();
    executor.awaitTermination(10, SECONDS);
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:22,代码来源:GuavaListenableFutureIT.java

示例6: simulateRollout

import com.google.common.util.concurrent.ListeningExecutorService; //导入方法依赖的package包/类
@Override
public ImmutableMap<PreFlopHandType, IncomeRate> simulateRollout( ImmutableMap<PreFlopHandType, IncomeRate> handTypeToIncomeRate, double tolerance, PrintWriter printWriter, int iteration) throws Exception
{
    if(printWriter != null)
    {
        synchronized (printWriter)
        {
            printWriter.println("HandType, Income Rate, Error, SD, Iteration");
            printWriter.flush();
        }
    }

    ImmutableSortedSet<PreFlopHandType> preflopHands = adaptor.adaptDeck(deckFactory.build());

    ImmutableMap.Builder<PreFlopHandType, IncomeRate> newIncomeRateBuilder = ImmutableMap.builder();

    int numCores = Runtime.getRuntime().availableProcessors();

    ListeningExecutorService threadPool = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numCores));

    for(PreFlopHandType handType : preflopHands)
    {
        IDeck deck = deckFactory.build();

        IncomeRateSimulationExecutor executor = new IncomeRateSimulationExecutor(handType, deck, handTypeToIncomeRate, tolerance, printWriter, iteration);

        ListenableFuture<IncomeRate> future = threadPool.submit(( Callable<IncomeRate>) executor );


    }

    threadPool.shutdown();
    threadPool.awaitTermination(1, TimeUnit.DAYS);

    return newIncomeRateBuilder.build();
}
 
开发者ID:williamrubens,项目名称:mossypokerbot,代码行数:37,代码来源:PreFlopRolloutSimulator.java


注:本文中的com.google.common.util.concurrent.ListeningExecutorService.awaitTermination方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。