Skip to content

Commit

Permalink
Do not use common ForkJoinPool on startup
Browse files Browse the repository at this point in the history
If there are other threads blocking this pool groovy might never be able to complete but wait forever.

See https://lists.apache.org/thread/hhxy11oqlpl6phfj945ntxy0c024yd2s
  • Loading branch information
florianmutter authored and daniellansun committed Sep 6, 2024
1 parent f40842b commit 426a85c
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -100,26 +99,19 @@ public Map<String, Set<String>> getDefaultImportClasses(final String[] packageNa

Map<String, Set<String>> result = new LinkedHashMap<>(2048);
try (GroovyClassLoader gcl = new GroovyClassLoader(this.getClass().getClassLoader())) {
CompletableFuture<Map<String, Set<String>>> javaDefaultImportsFuture =
CompletableFuture.supplyAsync(() -> doFindClasses(URI.create("jrt:/modules/java.base/"), "java", javaPackages));
try {
// groovy-core (Java source)
URI gcjLocation = DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.lang.GroovySystem")).toURI();
CompletableFuture<Map<String, Set<String>>> groovyDefaultImportsFuture1 =
CompletableFuture.supplyAsync(() -> doFindClasses(gcjLocation, "groovy", groovyPackages));
result.putAll(doFindClasses(gcjLocation, "groovy", groovyPackages));

// in production environment, groovy-core classes, e.g. `GroovySystem`(java class) and `ListenerLister`(groovy class) are all packaged in the groovy-core jar file,
// but in Groovy development environment, groovy-core classes are distributed in different directories
URI gcgLocation = DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.beans.ListenerList")).toURI();
CompletableFuture<Map<String, Set<String>>> groovyDefaultImportsFuture2 =
gcjLocation.equals(gcgLocation)
? CompletableFuture.completedFuture(Collections.emptyMap())
: CompletableFuture.supplyAsync(() -> doFindClasses(gcgLocation, "groovy", groovyPackages));

result.putAll(groovyDefaultImportsFuture1.get());
result.putAll(groovyDefaultImportsFuture2.get());
if (!gcjLocation.equals(gcgLocation)) {
result.putAll(doFindClasses(gcgLocation, "groovy", groovyPackages));
}
} finally {
result.putAll(javaDefaultImportsFuture.get());
result.putAll(doFindClasses(URI.create("jrt:/modules/java.base/"), "java", javaPackages));
}
} catch (Exception e) {
Logger logger = Logger.getLogger(getClass().getName());
Expand Down

0 comments on commit 426a85c

Please sign in to comment.