From c0775e3c4357e8d97a422eb1985a424b98964bbf Mon Sep 17 00:00:00 2001 From: Rafael Bey Date: Tue, 9 Jul 2024 16:53:11 -0400 Subject: [PATCH] pass thread context class loader when no explicit class loader is pass --- .../toPureGraph/PureModelBuilder.java | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) 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)