From cfce3dd0e573796ff3bd7297362580d90abfcceb Mon Sep 17 00:00:00 2001 From: Andriy Dmytruk Date: Mon, 29 Apr 2024 10:39:36 -0400 Subject: [PATCH] Do not parallelize definition building if it gives no advantage For the cases when there are 1 or 2 cores the fork join pool is of size 1 and therefore does not achieve parallelized execution. For this case we can load definitions on the main thread. --- .../main/java/io/micronaut/core/io/service/ServiceScanner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/io/micronaut/core/io/service/ServiceScanner.java b/core/src/main/java/io/micronaut/core/io/service/ServiceScanner.java index f122f8629af..4bca150cd90 100644 --- a/core/src/main/java/io/micronaut/core/io/service/ServiceScanner.java +++ b/core/src/main/java/io/micronaut/core/io/service/ServiceScanner.java @@ -239,7 +239,7 @@ public void collect(Collection values) { @Override public void collect(Collection values, boolean allowFork) { - if (allowFork) { + if (allowFork && ForkJoinPool.getCommonPoolParallelism() > 1) { ForkJoinPool.commonPool().invoke(this); for (RecursiveActionValuesCollector task : tasks) { task.join();