TINKERPOP-1644 Made the "counter" in GremlinGroovyScriptEngine static
It seems that this field should be static and shared across all instances as the script name seems to share space with other GroovyClassLoaders. Not sure what would happen in the case of collision, but there doesn't seem to be much harm in ensuring better uniqueness. This counter wasn't used for tracking the number of scripts actually processed or anything so it should be ok to make this change without fear of breaking anything. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/a06072b0 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/a06072b0 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/a06072b0 Branch: refs/heads/TINKERPOP-1642 Commit: a06072b0502f9b42fee4c68dba554b4991406c36 Parents: b29ba12 Author: Stephen Mallette <sp...@genoprime.com> Authored: Wed Mar 8 16:17:40 2017 -0500 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Fri Mar 10 11:12:37 2017 -0500 ---------------------------------------------------------------------- .../groovy/jsr223/GremlinGroovyScriptEngine.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a06072b0/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java index 5168130..3bcb06c 100644 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java +++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java @@ -196,7 +196,15 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl */ private final ManagedConcurrentValueMap<String, Closure> globalClosures = new ManagedConcurrentValueMap<>(ReferenceBundle.getHardBundle()); - private final AtomicLong counter = new AtomicLong(0L); + /** + * Ensures unique script names across all instances. + */ + private final static AtomicLong scriptNameCounter = new AtomicLong(0L); + + /** + * A counter for the instance that tracks the number of warnings issued during script compilations that exceeded + * the {@link #expectedCompilationTime}. + */ private final AtomicLong longRunCompilationCount = new AtomicLong(0L); /** @@ -799,7 +807,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl } private synchronized String generateScriptName() { - return SCRIPT + counter.incrementAndGet() + DOT_GROOVY; + return SCRIPT + scriptNameCounter.incrementAndGet() + DOT_GROOVY; } @SuppressWarnings("unchecked")