diff --git a/legend-sdlc-language-pure-compiler/src/main/java/org/finos/legend/sdlc/language/pure/compiler/toPureGraph/PureModelBuilder.java b/legend-sdlc-language-pure-compiler/src/main/java/org/finos/legend/sdlc/language/pure/compiler/toPureGraph/PureModelBuilder.java index c5e56e13f5..8bcf634c46 100644 --- a/legend-sdlc-language-pure-compiler/src/main/java/org/finos/legend/sdlc/language/pure/compiler/toPureGraph/PureModelBuilder.java +++ b/legend-sdlc-language-pure-compiler/src/main/java/org/finos/legend/sdlc/language/pure/compiler/toPureGraph/PureModelBuilder.java @@ -14,6 +14,11 @@ package org.finos.legend.sdlc.language.pure.compiler.toPureGraph; +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.ForkJoinWorkerThread; +import java.util.stream.Stream; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModelProcessParameter; import org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.CompilerExtension; @@ -27,11 +32,6 @@ import org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter; import org.finos.legend.sdlc.protocol.pure.v1.PureModelContextDataBuilder; -import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.ForkJoinWorkerThread; -import java.util.ServiceLoader; -import java.util.stream.Stream; - public class PureModelBuilder { private final PureModelContextDataBuilder contextDataBuilder; @@ -226,27 +226,23 @@ private PureModel buildPureModel(PureModelContextData pureModelContextData) { int parallelism = Runtime.getRuntime().availableProcessors(); - if (this.classLoader != null) - { - pool = new ForkJoinPool( - parallelism, - p -> + ClassLoader cl = Optional.ofNullable(this.classLoader) + .orElse(Thread.currentThread().getContextClassLoader()); + + pool = new ForkJoinPool( + parallelism, + p -> + { + ForkJoinWorkerThread workerThread = new ForkJoinWorkerThread(p) { - ForkJoinWorkerThread workerThread = new ForkJoinWorkerThread(p) - { - - }; - workerThread.setContextClassLoader(this.classLoader); - return workerThread; - }, - null, - false - ); - } - else - { - pool = new ForkJoinPool(parallelism); - } + + }; + workerThread.setContextClassLoader(cl); + return workerThread; + }, + null, + false + ); } PureModelProcessParameter pureModelProcessParameter = PureModelProcessParameter.newBuilder() .withPackagePrefix(this.packagePrefix)