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/01/15 15:04:00 UTC
[groovy] branch missing-dot updated (757360b -> 804ade1)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch missing-dot
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from 757360b Revert "Tweak resource management in GINQ further"
new 847cd26 Tweak resource management in GINQ further
new 804ade1 Try to address javadoc issue
The 2 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.
Summary of changes:
.../collection/runtime/QueryableHelper.groovy | 30 +++++++++++++++++-----
.../groovy-ginq/src/spec/doc/ginq-userguide.adoc | 6 +++--
.../test/org/apache/groovy/ginq/GinqTest.groovy | 6 ++---
3 files changed, 30 insertions(+), 12 deletions(-)
[groovy] 02/02: Try to address javadoc issue
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch missing-dot
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 804ade18e69162c25be44cc418867ca2427913b7
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jan 15 23:02:45 2021 +0800
Try to address javadoc issue
---
.../groovy/ginq/provider/collection/runtime/QueryableHelper.groovy | 1 -
1 file changed, 1 deletion(-)
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 0825dcb..2ea7245 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
@@ -106,7 +106,6 @@ class QueryableHelper {
* Shutdown to release resources
*
* @param mode 0: immediate, 1: abort
- * @return list of tasks that never commenced execution
*/
static List<Runnable> shutdown(int mode) {
if (0 == mode) {
[groovy] 01/02: Tweak resource management in GINQ further
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch missing-dot
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 847cd26f649dbf0ffd38df99c554a76df3c9f571
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jan 15 23:00:49 2021 +0800
Tweak resource management in GINQ further
This reverts commit 757360be
---
.../collection/runtime/QueryableHelper.groovy | 31 +++++++++++++++++-----
.../groovy-ginq/src/spec/doc/ginq-userguide.adoc | 6 +++--
.../test/org/apache/groovy/ginq/GinqTest.groovy | 6 ++---
3 files changed, 31 insertions(+), 12 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 b5b1bf2..0825dcb 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
@@ -23,7 +23,9 @@ import groovy.transform.CompileStatic
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
+import java.util.concurrent.ThreadFactory
import java.util.concurrent.TimeUnit
+import java.util.concurrent.atomic.AtomicInteger
import java.util.function.Function
import java.util.function.Supplier
import java.util.stream.Collectors
@@ -77,11 +79,11 @@ class QueryableHelper {
}
static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
- return CompletableFuture.supplyAsync(supplier, THREAD_POOL)
+ return CompletableFuture.supplyAsync(supplier, ThreadPoolHolder.THREAD_POOL)
}
static <T, U> CompletableFuture<U> supplyAsync(Function<? super T, ? extends U> function, T param) {
- return CompletableFuture.supplyAsync(() -> { function.apply(param) }, THREAD_POOL)
+ return CompletableFuture.supplyAsync(() -> { function.apply(param) }, ThreadPoolHolder.THREAD_POOL)
}
static boolean isParallel() {
@@ -104,24 +106,39 @@ class QueryableHelper {
* Shutdown to release resources
*
* @param mode 0: immediate, 1: abort
+ * @return list of tasks that never commenced execution
*/
- static shutdown(int mode) {
+ static List<Runnable> shutdown(int mode) {
if (0 == mode) {
- THREAD_POOL.shutdown()
- while (!THREAD_POOL.awaitTermination(250, TimeUnit.MILLISECONDS)) {
+ ThreadPoolHolder.THREAD_POOL.shutdown()
+ while (!ThreadPoolHolder.THREAD_POOL.awaitTermination(250, TimeUnit.MILLISECONDS)) {
// do nothing, just wait to terminate
}
+ return Collections.emptyList()
} else if (1 == mode) {
- THREAD_POOL.shutdownNow()
+ return ThreadPoolHolder.THREAD_POOL.shutdownNow()
} else {
throw new IllegalArgumentException("Invalid mode: $mode")
}
}
private static final ThreadLocal<Map<String, Object>> VAR_HOLDER = ThreadLocal.<Map<String, Object>> withInitial(() -> new LinkedHashMap<>())
- private static final ExecutorService THREAD_POOL = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
private static final String PARALLEL = "parallel"
private static final String TRUE_STR = "true"
private QueryableHelper() {}
+
+ private static class ThreadPoolHolder {
+ static final ExecutorService THREAD_POOL = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactory() {
+ private static final String THREAD_NAME_PREFIX = 'Thread-GINQ-'
+ private static final AtomicInteger SEQ = new AtomicInteger(0)
+
+ @Override
+ Thread newThread(Runnable r) {
+ return new Thread(r, "${THREAD_NAME_PREFIX}${SEQ.getAndIncrement()}")
+ }
+ })
+
+ private ThreadPoolHolder() {}
+ }
}
diff --git a/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc b/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
index 27b2a80..f9863b0 100644
--- a/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
+++ b/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
@@ -697,13 +697,15 @@ Parallel querying is especially efficient when querying big data sources. It is
include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_tips_08,indent=0]
----
-As parallel querying will use a shared thread pool, the following code should be executed to release resources before all GINQ statements are completed, or JVM will not exit. The code will wait util all tasks of theads are completed.
+As parallel querying will use a shared thread pool, the following code should be executed to release resources before all GINQ statements are completed, otherwise JVM will not exit. The code will wait util all tasks of theads are completed.
[source, groovy]
----
include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_tips_09,indent=0]
----
+[WARNING]
+Once `shutdown` is issued, parallel querying can not work anymore.
-The following code is equivalent to the above code:
+The following code is equivalent to the above code, in other words, `immediate` is optional:
[source, groovy]
----
include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_tips_10,indent=0]
diff --git a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
index af8c7d2..62f2f72 100644
--- a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
+++ b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
@@ -5703,7 +5703,7 @@ class GinqTest {
shutdown
}
// end::ginq_tips_09[]
- assert QueryableHelper.THREAD_POOL.isShutdown() && QueryableHelper.THREAD_POOL.isTerminated()
+ assert QueryableHelper.ThreadPoolHolder.THREAD_POOL.isShutdown() && QueryableHelper.ThreadPoolHolder.THREAD_POOL.isTerminated()
'''
}
@@ -5716,7 +5716,7 @@ class GinqTest {
shutdown immediate
}
// end::ginq_tips_10[]
- assert QueryableHelper.THREAD_POOL.isShutdown() && QueryableHelper.THREAD_POOL.isTerminated()
+ assert QueryableHelper.ThreadPoolHolder.THREAD_POOL.isShutdown() && QueryableHelper.ThreadPoolHolder.THREAD_POOL.isTerminated()
'''
}
@@ -5729,7 +5729,7 @@ class GinqTest {
shutdown abort
}
// end::ginq_tips_11[]
- assert QueryableHelper.THREAD_POOL.isShutdown()
+ assert QueryableHelper.ThreadPoolHolder.THREAD_POOL.isShutdown()
'''
}