use of java8.util.concurrent.ForkJoinWorkerThread in project streamsupport by stefan-zobel.
the class RecursiveActionTest method testWorkerGetPool.
/**
* getPool of current thread in pool returns its pool
*/
public void testWorkerGetPool() {
final ForkJoinPool mainPool = mainPool();
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
ForkJoinWorkerThread w = (ForkJoinWorkerThread) Thread.currentThread();
assertSame(mainPool, w.getPool());
}
};
testInvokeOnPool(mainPool, a);
}
use of java8.util.concurrent.ForkJoinWorkerThread in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testPollSubmission.
// jdk9
/**
* pollSubmission returns unexecuted submitted task, if present
*/
public void testPollSubmission() {
final CountDownLatch done = new CountDownLatch(1);
final ForkJoinTask<?> a = ForkJoinTask.adapt(awaiter(done));
final ForkJoinTask<?> b = ForkJoinTask.adapt(awaiter(done));
final ForkJoinTask<?> c = ForkJoinTask.adapt(awaiter(done));
final ForkJoinPool p = singletonPool();
PoolCleaner cleaner = null;
try {
cleaner = cleaner(p, done);
Thread external = new Thread(new CheckedRunnable() {
public void realRun() {
p.execute(a);
p.execute(b);
p.execute(c);
}
});
@SuppressWarnings("serial") RecursiveAction s = new CheckedRecursiveAction() {
protected void realCompute() {
external.start();
try {
external.join();
} catch (Exception ex) {
threadUnexpectedException(ex);
}
assertTrue(p.hasQueuedSubmissions());
assertTrue(Thread.currentThread() instanceof ForkJoinWorkerThread);
ForkJoinTask<?> r = ForkJoinTask.pollSubmission();
assertTrue(r == a || r == b || r == c);
assertFalse(r.isDone());
}
};
p.invoke(s);
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinWorkerThread in project streamsupport by stefan-zobel.
the class RecursiveActionTest method testWorkerGetPoolIndex.
/**
* getPoolIndex of current thread in pool returns 0 <= value < poolSize
*/
public void testWorkerGetPoolIndex() {
final ForkJoinPool mainPool = mainPool();
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
ForkJoinWorkerThread w = (ForkJoinWorkerThread) Thread.currentThread();
assertTrue(w.getPoolIndex() >= 0);
// pool size can shrink after assigning index, so cannot check
// assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
}
};
testInvokeOnPool(mainPool, a);
}
Aggregations