groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Trivial refactoring: Use `AtomicInteger` instead of `synchronized`(closes #733)
Date Tue, 29 May 2018 04:31:17 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 8a62b0e0a -> 0ae1a4927


Trivial refactoring: Use `AtomicInteger` instead of `synchronized`(closes #733)

(cherry picked from commit b416bee)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/0ae1a492
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/0ae1a492
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/0ae1a492

Branch: refs/heads/GROOVY_2_5_X
Commit: 0ae1a49277a0a0d12b88c6fd48089122b6d37203
Parents: 8a62b0e
Author: sunlan <sunlan@apache.org>
Authored: Tue May 29 12:26:27 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue May 29 12:31:12 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/lang/GroovyShell.java | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/0ae1a492/src/main/groovy/groovy/lang/GroovyShell.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/GroovyShell.java b/src/main/groovy/groovy/lang/GroovyShell.java
index f155b30..53bc6e6 100644
--- a/src/main/groovy/groovy/lang/GroovyShell.java
+++ b/src/main/groovy/groovy/lang/GroovyShell.java
@@ -38,6 +38,7 @@ import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import static org.codehaus.groovy.runtime.InvokerHelper.MAIN_METHOD_NAME;
 
@@ -54,7 +55,7 @@ public class GroovyShell extends GroovyObjectSupport {
     private static final String[] EMPTY_STRING_ARRAY = new String[0];
 
     private final Binding context;
-    private int counter;
+    private final AtomicInteger counter = new AtomicInteger(0);
     private final CompilerConfiguration config;
     private GroovyClassLoader loader;
 
@@ -603,7 +604,7 @@ public class GroovyShell extends GroovyObjectSupport {
         return parse(in, generateScriptName());
     }
 
-    protected synchronized String generateScriptName() {
-        return "Script" + (++counter) + ".groovy";
+    protected String generateScriptName() {
+        return "Script" + counter.incrementAndGet() + ".groovy";
     }
 }


Mime
View raw message