You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/07/19 06:43:48 UTC

[groovy] branch master updated: Tweak thread pool for GINQ

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 5263a17  Tweak thread pool for GINQ
5263a17 is described below

commit 5263a170cb6577533ba6c04e3175fe8b1a3ca4d5
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Jul 19 14:43:36 2021 +0800

    Tweak thread pool for GINQ
---
 .../provider/collection/runtime/QueryableHelper.groovy     | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelper.groovy b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelper.groovy
index 75274de..aa23763 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelper.groovy
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableHelper.groovy
@@ -20,6 +20,7 @@ package org.apache.groovy.ginq.provider.collection.runtime
 
 import groovy.transform.CompileStatic
 import groovy.transform.Internal
+import org.apache.groovy.util.SystemUtil
 
 import java.util.concurrent.Callable
 import java.util.concurrent.CompletableFuture
@@ -27,6 +28,7 @@ import java.util.concurrent.ExecutorService
 import java.util.concurrent.Executors
 import java.util.concurrent.ForkJoinPool
 import java.util.concurrent.ForkJoinTask
+import java.util.concurrent.ForkJoinWorkerThread
 import java.util.concurrent.TimeUnit
 import java.util.function.Function
 import java.util.function.Supplier
@@ -139,14 +141,20 @@ class QueryableHelper {
     private QueryableHelper() {}
 
     private static class ThreadPoolHolder {
+        static int fjSeq
         static int seq
-        static final ExecutorService THREAD_POOL = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1, (Runnable r) -> {
+        static final int PARALLELISM = SystemUtil.getIntegerSafe("groovy.ginq.parallelism", Runtime.getRuntime().availableProcessors() + 1);
+        static final ForkJoinPool FORKJOIN_POOL = new ForkJoinPool(PARALLELISM, (ForkJoinPool pool) -> {
+            ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool)
+            worker.setName("ginq-fj-thread-${fjSeq++}")
+            return worker
+        }, null, false)
+        static final ExecutorService THREAD_POOL = Executors.newFixedThreadPool(PARALLELISM, (Runnable r) -> {
             Thread t = new Thread(r)
-            t.setName("ginq-thread-" + seq++)
+            t.setName("ginq-thread-${seq++}")
             t.setDaemon(true)
             return t
         })
-        static final ForkJoinPool FORKJOIN_POOL = new ForkJoinPool(Runtime.getRuntime().availableProcessors() + 1)
         private ThreadPoolHolder() {}
     }
 }