Skip to content

Commit

Permalink
Automatic merge of master into galahad
Browse files Browse the repository at this point in the history
  • Loading branch information
OracleLabsAutomation committed Jul 3, 2024
2 parents 44b6e58 + 08b5c19 commit f75c556
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,23 @@ public Object execute(VirtualFrame frame) {

}

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

public static void runInVirtualThread(Runnable runnable) throws Throwable {
Expand Down

0 comments on commit f75c556

Please sign in to comment.