You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/07/19 19:19:38 UTC

[39/50] [abbrv] tinkerpop git commit: Wrapped future in WeakReference

Wrapped future in WeakReference

This is an add-on change that should have been in place on TINKERPOP-1714. This should allow the result to be garbage collected without waiting for the timeout. CTR


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2ba4104a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2ba4104a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2ba4104a

Branch: refs/heads/TINKERPOP-1716
Commit: 2ba4104aaa3e93b0155331b6f5e410a0bd59b0d3
Parents: 5335f4a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jul 17 10:39:07 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Jul 17 10:39:07 2017 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/groovy/engine/GremlinExecutor.java       | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2ba4104a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
index d646a8c..d02d773 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
@@ -38,6 +38,7 @@ import javax.script.SimpleBindings;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -324,11 +325,12 @@ public class GremlinExecutor implements AutoCloseable {
             return null;
         });
 
-        final Future<?> executionFuture = executorService.submit(evalFuture);
+        final WeakReference<Future<?>> executionFuture = new WeakReference<>(executorService.submit(evalFuture));
         if (scriptEvalTimeOut > 0) {
             // Schedule a timeout in the thread pool for future execution
             scheduledExecutorService.schedule(() -> {
-                if (executionFuture.cancel(true)) {
+                final Future<?> f = executionFuture.get();
+                if (f != null && f.cancel(true)) {
                     lifeCycle.getAfterTimeout().orElse(afterTimeout).accept(bindings);
                     evaluationFuture.completeExceptionally(new TimeoutException(
                             String.format("Script evaluation exceeded the configured 'scriptEvaluationTimeout' threshold of %s ms or evaluation was otherwise cancelled directly for request [%s]", scriptEvalTimeOut, script)));