本文整理匯總了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());
}
示例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);
}
示例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();
}
}
}
示例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();
}
示例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);
}
示例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();
}