This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 7e94be408b backport from Groovy 5 for better parallel support
7e94be408b is described below
commit 7e94be408b2264e6ea6f1068123bc2ff725a0e9a
Author: Paul King <[email protected]>
AuthorDate: Wed Sep 25 21:57:55 2024 +1000
backport from Groovy 5 for better parallel support
---
src/main/java/groovy/lang/GroovyClassLoader.java | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/main/java/groovy/lang/GroovyClassLoader.java
b/src/main/java/groovy/lang/GroovyClassLoader.java
index fc3c1bfde4..397eafd9e7 100644
--- a/src/main/java/groovy/lang/GroovyClassLoader.java
+++ b/src/main/java/groovy/lang/GroovyClassLoader.java
@@ -77,6 +77,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* A ClassLoader which can load Groovy classes. The loaded classes are cached,
@@ -104,8 +105,7 @@ public class GroovyClassLoader extends URLClassLoader {
private final CompilerConfiguration config;
private String sourceEncoding;
private Boolean recompile;
- // use 1000000 as offset to avoid conflicts with names from the GroovyShell
- private static int scriptNameCounter = 1000000;
+ private static final AtomicInteger scriptNameCounter = new
AtomicInteger(1_000_000); // 1,000,000 avoids conflicts with names from the
GroovyShell
static {
registerAsParallelCapable();
@@ -282,8 +282,7 @@ public class GroovyClassLoader extends URLClassLoader {
}
public synchronized String generateScriptName() {
- scriptNameCounter++;
- return "script" + scriptNameCounter + ".groovy";
+ return "script" + scriptNameCounter.getAndIncrement() + ".groovy";
}
public Class parseClass(final Reader reader, final String fileName) throws
CompilationFailedException {