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

(cherry picked from commit 426a85c)
  • Loading branch information
florianmutter authored and daniellansun committed Sep 6, 2024
1 parent 06b2a98 commit 690527f
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 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 @@ -93,25 +92,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 {
URI gsLocation = DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.lang.GroovySystem")).toURI();
CompletableFuture<Map<String, Set<String>>> groovyDefaultImportsFuture1 =
CompletableFuture.supplyAsync(() -> doFindClasses(gsLocation, "groovy", groovyPackages));
// groovy-core (Java source)
URI gcjLocation = DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.lang.GroovySystem")).toURI();
result.putAll(doFindClasses(gcjLocation, "groovy", groovyPackages));

// in production environment, groovy-core classes, e.g. `GroovySystem`(java class) and `GrapeIvy`(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 giLocation = DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.grape.GrapeIvy")).toURI();
CompletableFuture<Map<String, Set<String>>> groovyDefaultImportsFuture2 =
gsLocation.equals(giLocation)
? CompletableFuture.completedFuture(Collections.emptyMap())
: CompletableFuture.supplyAsync(() -> doFindClasses(giLocation, "groovy", groovyPackages));

result.putAll(groovyDefaultImportsFuture1.get());
result.putAll(groovyDefaultImportsFuture2.get());
URI gcgLocation = DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.beans.ListenerList")).toURI();
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 ignore) {
Logger logger = Logger.getLogger(getClass().getName());
Expand Down

0 comments on commit 690527f

Please sign in to comment.