File tree 1 file changed +7
-4
lines changed
src/main/java/groovy/lang
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 78
78
import java .util .Collection ;
79
79
import java .util .Enumeration ;
80
80
import java .util .Map ;
81
+ import java .util .concurrent .atomic .AtomicInteger ;
81
82
82
83
/**
83
84
* A ClassLoader which can load Groovy classes. The loaded classes are cached,
@@ -105,8 +106,11 @@ public class GroovyClassLoader extends URLClassLoader {
105
106
private final CompilerConfiguration config ;
106
107
private String sourceEncoding ;
107
108
private Boolean recompile ;
108
- // use 1000000 as offset to avoid conflicts with names from the GroovyShell
109
- private static int scriptNameCounter = 1000000 ;
109
+ private static final AtomicInteger scriptNameCounter = new AtomicInteger (1_000_000 ); // 1,000,000 avoids conflicts with names from the GroovyShell
110
+
111
+ static {
112
+ registerAsParallelCapable ();
113
+ }
110
114
111
115
private GroovyResourceLoader resourceLoader = new GroovyResourceLoader () {
112
116
public URL loadGroovySource (final String filename ) throws MalformedURLException {
@@ -272,8 +276,7 @@ public Class parseClass(String text) throws CompilationFailedException {
272
276
}
273
277
274
278
public synchronized String generateScriptName () {
275
- scriptNameCounter ++;
276
- return "script" + scriptNameCounter + ".groovy" ;
279
+ return "script" + scriptNameCounter .getAndIncrement () + ".groovy" ;
277
280
}
278
281
279
282
public Class parseClass (final Reader reader , final String fileName ) throws CompilationFailedException {
You can’t perform that action at this time.
0 commit comments