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 2023/04/15 11:20:08 UTC
[groovy] branch GROOVY-11015 created (now 4408a4593f)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch GROOVY-11015
in repository https://gitbox.apache.org/repos/asf/groovy.git
at 4408a4593f GROOVY-11015: [GINQ]Leverage the power of Virtual Thread
This branch includes the following new commits:
new 4408a4593f GROOVY-11015: [GINQ]Leverage the power of Virtual Thread
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[groovy] 01/01: GROOVY-11015: [GINQ]Leverage the power of Virtual Thread
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-11015
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 4408a4593f31def5793841bce547e90342506c97
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Apr 15 19:19:51 2023 +0800
GROOVY-11015: [GINQ]Leverage the power of Virtual Thread
---
.../collection/runtime/QueryableHelper.groovy | 31 +++++++++++++++++-----
1 file changed, 25 insertions(+), 6 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 aa2376399e..1ffd8e21aa 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
@@ -18,6 +18,7 @@
*/
package org.apache.groovy.ginq.provider.collection.runtime
+import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import groovy.transform.Internal
import org.apache.groovy.util.SystemUtil
@@ -32,6 +33,8 @@ import java.util.concurrent.ForkJoinWorkerThread
import java.util.concurrent.TimeUnit
import java.util.function.Function
import java.util.function.Supplier
+import java.util.logging.Level
+import java.util.logging.Logger
import java.util.stream.Collectors
import static org.apache.groovy.ginq.provider.collection.runtime.Queryable.from
@@ -141,6 +144,7 @@ class QueryableHelper {
private QueryableHelper() {}
private static class ThreadPoolHolder {
+ private static final Logger LOGGER = Logger.getLogger(ThreadPoolHolder.class.getName());
static int fjSeq
static int seq
static final int PARALLELISM = SystemUtil.getIntegerSafe("groovy.ginq.parallelism", Runtime.getRuntime().availableProcessors() + 1);
@@ -149,12 +153,27 @@ class QueryableHelper {
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.setDaemon(true)
- return t
- })
+ static final ExecutorService THREAD_POOL = createExecutorService()
+
+ @CompileDynamic
+ private static ExecutorService createExecutorService() {
+ var threadPool
+ try {
+ threadPool = Executors.newVirtualThreadPerTaskExecutor()
+ } catch (e) {
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.fine("Failed to create VirtualThreadPerTaskExecutor.\n${e.asString()}")
+ }
+ threadPool = Executors.newFixedThreadPool(PARALLELISM, (Runnable r) -> {
+ Thread t = new Thread(r)
+ t.setName("ginq-thread-${seq++}")
+ t.setDaemon(true)
+ return t
+ })
+ }
+ return threadPool
+ }
+
private ThreadPoolHolder() {}
}
}