@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(); } } } }
@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(); } } } }
@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); }
boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { return executor.awaitTermination(timeout, unit); }
@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(); } }
@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); } }
@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(); } } } }
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); } }
@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"))); } } }
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { LOGGER.warn("The thread pool joining has been interrupted", e);
/** * 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); }
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()); }
@Test(expected = CPUReactiveAuditException.class) public void awaitTermination() throws InterruptedException { TestTools.strict.commit(); e.awaitTermination(1, TimeUnit.MILLISECONDS); }
@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"); } } }
assert Thread.currentThread() == mainThread; boolean quiescent = executorService.awaitTermination(100, TimeUnit.MILLISECONDS); if (timing != null && !quiescent) { long curTime = System.nanoTime();