/** * Finds missing PoolCleaners */ void checkForkJoinPoolThreadLeaks() throws InterruptedException { Thread[] survivors = new Thread[7]; int count = Thread.enumerate(survivors); for (int i = 0; i < count; i++) { Thread thread = survivors[i]; String name = thread.getName(); if (name.startsWith("ForkJoinPool-")) { // give thread some time to terminate thread.join(LONG_DELAY_MS); if (thread.isAlive()) tearDownFail("Found leaked ForkJoinPool thread thread=%s", thread); } } if (!ForkJoinPool.commonPool() .awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) tearDownFail("ForkJoin common pool thread stuck"); }
@Override protected boolean matchesSafely(Object ignored, Description description) { DescriptionBuilder desc = new DescriptionBuilder(description); if (context.removalListenerType == Listener.CONSUMING) { List<RemovalNotification<Integer, Integer>> notifications = context.consumedNotifications(); ForkJoinPool.commonPool().awaitQuiescence(10, TimeUnit.SECONDS); int size = 0; for (RemovalNotification<?, ?> notification : notifications) { if (notification.getCause() == cause) { checkNotification(notification); size++; } } desc.expectThat("notification count", size, is(count)); } return desc.matches(); }
@Override protected boolean matchesSafely(CacheContext context, Description description) { if (!context.isRecordingStats()) { return true; } CacheStats stats = context.stats(); desc = new DescriptionBuilder(description); ForkJoinPool.commonPool().awaitQuiescence(10, TimeUnit.SECONDS); switch (type) { case HIT: return desc.expectThat(type.name(), stats.hitCount(), is(count)).matches(); case MISS: return desc.expectThat(type.name(), stats.missCount(), is(count)).matches(); case EVICTION_COUNT: return desc.expectThat(type.name(), stats.evictionCount(), is(count)).matches(); case EVICTION_WEIGHT: return desc.expectThat(type.name(), stats.evictionWeight(), is(count)).matches(); case LOAD_SUCCESS: return desc.expectThat(type.name(), stats.loadSuccessCount(), is(count)).matches(); case LOAD_FAILURE: return desc.expectThat(type.name(), stats.loadFailureCount(), is(count)).matches(); default: throw new AssertionError("Unknown stats type"); } }
private void initAllClasses() { final ForkJoinPool executor = new ForkJoinPool(Runtime.getRuntime().availableProcessors()); Set<Path> uniquePaths = new TreeSet<>(Comparator.comparing(ImageClassLoader::toRealPath)); uniquePaths.addAll( Arrays.stream(classpath) .flatMap(ImageClassLoader::toClassPathEntries) .collect(Collectors.toList())); uniquePaths.parallelStream().forEach(path -> loadClassesFromPath(executor, path)); executor.awaitQuiescence(CLASS_LOADING_TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); }
ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.DAYS);
"ForkJoinPool-1-worker-1" [...] Object.wait() [...] java.lang.Thread.State: WAITING (on object monitor) [...] at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:995) [...] at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) [...] "main" [...] waiting on condition [...] java.lang.Thread.State: WAITING (parking) [...] at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231) [...] at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1445) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool.awaitQuiescence(ForkJoinPool.java:3097) [...]
pool.awaitQuiescence(2L, TimeUnit.SECONDS);
public static void main(String[] args) { // the default `commonPool` should be sufficient for many cases. ForkJoinPool pool = ForkJoinPool.commonPool(); // The root of your task that may spawn other tasks. // Make sure it submits the additional tasks to the same executor that it is in. Runnable rootTask = new YourTask(pool); pool.execute(rootTask); pool.awaitQuiescence(...); // that's it. }
walker.visitTargets(asFactory(transforms), Util.await(future)); } else { pool.awaitQuiescence(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
@Test(expected = CPUReactiveAuditException.class) public void awaitQuiescence() throws InterruptedException { TestTools.strict.commit(); e.awaitQuiescence(1, TimeUnit.MILLISECONDS); }
pool.awaitQuiescence(Long.MAX_VALUE, TimeUnit.NANOSECONDS); inner.providers.forEach(i -> pool.execute(() -> i.processor().onProcessEnd())); pool.awaitQuiescence(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.MINUTES); }));
@Test public void awaitQuiesence() { CompletableFuture<Void> cf = aq.supplyThenAccept(); assertFalse(cf.isDone()); ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.SECONDS); assertTrue(cf.isDone()); } }