Skip to content

Commit 08b5c19

Browse files
committed
[GR-54729] AbstractPolyglotTest#threadPool(N, vthreads) should create N threads and not more
PullRequest: graal/18185
2 parents 5ea8ee7 + 0988ef1 commit 08b5c19

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/AbstractPolyglotTest.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,23 @@ public Object execute(VirtualFrame frame) {
487487

488488
}
489489

490-
// When using this method, the caller test should use:
491-
// Assume.assumeFalse(vthreads && !canCreateVirtualThreads());
492-
// at the start of the test to avoid extra unnecessary work.
490+
/**
491+
* When using this method, the caller test should use:
492+
* {@code Assume.assumeFalse(vthreads && !canCreateVirtualThreads());} at the start of the test
493+
* to avoid extra unnecessary work.
494+
*/
493495
public static ExecutorService threadPool(int threads, boolean vthreads) {
494-
return vthreads ? Executors.newVirtualThreadPerTaskExecutor() : Executors.newFixedThreadPool(threads);
496+
if (vthreads) {
497+
/*
498+
* It might be tempting to use Executors.newVirtualThreadPerTaskExecutor() here but that
499+
* would then be surprising for the caller which expects a thread pool with N threads
500+
* and not more. For example, if many tasks are sent and a new thread is created for
501+
* each task it tests something different from executing multiple tasks per thread.
502+
*/
503+
return Executors.newFixedThreadPool(threads, runnable -> Thread.ofVirtual().unstarted(runnable));
504+
} else {
505+
return Executors.newFixedThreadPool(threads);
506+
}
495507
}
496508

497509
public static void runInVirtualThread(Runnable runnable) throws Throwable {

0 commit comments

Comments
 (0)