本文整理了Java中java.util.concurrent.ForkJoinPool.awaitTermination()
方法的一些代码示例,展示了ForkJoinPool.awaitTermination()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ForkJoinPool.awaitTermination()
方法的具体详情如下:
包路径:java.util.concurrent.ForkJoinPool
类名称:ForkJoinPool
方法名:awaitTermination
[英]Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first. Note that the #commonPool() never terminates until program shutdown so this method will always time out.
[中]阻塞,直到所有任务在关闭请求后完成执行,或超时发生,或当前线程中断(以先发生的为准)。请注意,#commonPool()在程序关闭之前不会终止,因此此方法将始终超时。
代码示例来源:origin: spring-projects/spring-framework
@Override
public void destroy() {
if (this.forkJoinPool != null) {
// Ignored for the common pool.
this.forkJoinPool.shutdown();
// Wait for all tasks to terminate - works for the common pool as well.
if (this.awaitTerminationSeconds > 0) {
try {
this.forkJoinPool.awaitTermination(this.awaitTerminationSeconds, TimeUnit.SECONDS);
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
代码示例来源:origin: org.springframework/spring-context
@Override
public void destroy() {
if (this.forkJoinPool != null) {
// Ignored for the common pool.
this.forkJoinPool.shutdown();
// Wait for all tasks to terminate - works for the common pool as well.
if (this.awaitTerminationSeconds > 0) {
try {
this.forkJoinPool.awaitTermination(this.awaitTerminationSeconds, TimeUnit.SECONDS);
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
代码示例来源:origin: palantir/atlasdb
@Test
public void testCreatingMultipleTablesAtOnce() throws InterruptedException {
int threadCount = 16;
CyclicBarrier barrier = new CyclicBarrier(threadCount);
ForkJoinPool threadPool = new ForkJoinPool(threadCount);
threadPool.submit(() ->
IntStream.range(0, threadCount).parallel().forEach(i -> {
try {
barrier.await();
slowTimeoutKvs.createTable(GOOD_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA);
} catch (BrokenBarrierException | InterruptedException e) {
// Do nothing
}
}));
threadPool.shutdown();
Preconditions.checkState(threadPool.awaitTermination(90, TimeUnit.SECONDS),
"Not all table creation threads completed within the time limit");
slowTimeoutKvs.dropTable(GOOD_TABLE);
}
代码示例来源:origin: de.unijena.bioinf/jjobs-core
boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
return executor.awaitTermination(timeout, unit);
}
代码示例来源:origin: PreferredAI/venom
@Override
public void interruptAndClose() throws Exception {
interrupt();
try {
crawlerThread.join();
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (final InterruptedException e) {
LOGGER.warn("The joining has been interrupted!", e);
Thread.currentThread().interrupt();
}
}
代码示例来源:origin: kompics/kompics
@Override
public void shutdown() {
pool.shutdown();
try {
if (!pool.awaitTermination(Kompics.SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS)) {
Kompics.logger.warn("Failed orderly Kompics shutdown");
}
} catch (InterruptedException ex) {
Kompics.logger.warn("Failed orderly Kompics shutdown", ex);
}
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public void destroy() {
if (this.forkJoinPool != null) {
// Ignored for the common pool.
this.forkJoinPool.shutdown();
// Wait for all tasks to terminate - works for the common pool as well.
if (this.awaitTerminationSeconds > 0) {
try {
this.forkJoinPool.awaitTermination(this.awaitTerminationSeconds, TimeUnit.SECONDS);
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
代码示例来源:origin: addthis/hydra
private void joinProcessors() {
mapperPool.shutdown();
try {
if (!mapperPool.awaitTermination(task.getTaskFinishTimeout(), TimeUnit.SECONDS)) {
throw new RuntimeException("Mapper pool did not terminate after " +
task.getTaskFinishTimeout() + " seconds.");
}
} catch (InterruptedException ex) {
log.error("Interrupted while waiting for mapper pool termination.");
Throwables.propagate(ex);
}
}
代码示例来源:origin: org.talend.sdk.component/documentation
@Override
public void close() {
executorService.shutdown();
tasks.forEach(it -> {
try {
it.get();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
} catch (final ExecutionException e) {
final Throwable cause = e.getCause();
errors.add(cause);
throw new IllegalStateException(cause);
}
});
try {
if (!executorService.awaitTermination(5, SECONDS)) {
executorService.shutdownNow();
}
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
if (!errors.isEmpty()) {
throw new IllegalStateException(errors.stream().map(Throwable::getMessage).collect(joining("\n")));
}
}
}
代码示例来源:origin: PreferredAI/venom
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
LOGGER.warn("The thread pool joining has been interrupted", e);
代码示例来源:origin: habanero-rice/PCDP
/**
* A method for altering the number of worker threads used by PCDP at
* runtime. It is the programmer's responsibility to ensure that no tasks
* are executing or pending on the runtime when this call is made.
*
* @param numWorkers The number of workers to switch to using.
* @throws InterruptedException An error occurs shutting down the existing
* runtime instance.
*/
public static void resizeWorkerThreads(final int numWorkers)
throws InterruptedException {
taskPool.shutdown();
boolean terminated = taskPool.awaitTermination(10, TimeUnit.SECONDS);
assert (terminated);
SystemProperty.numWorkers.set(numWorkers);
taskPool = new ForkJoinPool(numWorkers);
}
代码示例来源:origin: xuminwlt/j360-jdk
public static void main(String[] args){
int array[]=new int[100];
Task task=new Task(array,0,100);
ForkJoinPool pool=new ForkJoinPool();
pool.execute(task);
pool.shutdown();
try {
pool.awaitTermination(1, TimeUnit.DAYS);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (task.isCompletedAbnormally()) {
System.out.printf("Main: An exception has ocurred\n");
System.out.printf("Main: %s\n",task.getException());
}
System.out.printf("Main: Result: %d",task.join());
}
代码示例来源:origin: octo-online/reactive-audit
@Test(expected = CPUReactiveAuditException.class)
public void awaitTermination()
throws InterruptedException
{
TestTools.strict.commit();
e.awaitTermination(1, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: org.sonarsource.scm.git/sonar-scm-git-plugin
@Override
public void blame(BlameInput input, BlameOutput output) {
File basedir = input.fileSystem().baseDir();
try (Repository repo = buildRepository(basedir); Git git = Git.wrap(repo)) {
File gitBaseDir = repo.getWorkTree();
if (Files.isRegularFile(gitBaseDir.toPath().resolve(".git/shallow"))) {
LOG.warn("Shallow clone detected, no blame information will be provided. "
+ "You can convert to non-shallow with 'git fetch --unshallow'.");
analysisWarnings.addUnique("Shallow clone detected during the analysis. "
+ "Some files will miss SCM information. This will affect features like auto-assignment of issues. "
+ "Please configure your build to disable shallow clone.");
return;
}
Stream<InputFile> stream = StreamSupport.stream(input.filesToBlame().spliterator(), true);
ForkJoinPool forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), new GitThreadFactory(), null, false);
forkJoinPool.submit(() -> stream.forEach(inputFile -> blame(output, git, gitBaseDir, inputFile)));
try {
forkJoinPool.shutdown();
forkJoinPool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
} catch (InterruptedException e) {
LOG.info("Git blame interrupted");
}
}
}
代码示例来源:origin: com.oracle.substratevm/pointsto
assert Thread.currentThread() == mainThread;
boolean quiescent = executorService.awaitTermination(100, TimeUnit.MILLISECONDS);
if (timing != null && !quiescent) {
long curTime = System.nanoTime();
内容来源于网络,如有侵权,请联系作者删除!