diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-07-29 17:06:24 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-08-03 11:33:44 +0200 |
| commit | ebc6cdd08a0d8dac045305839421b726ae5c91b3 (patch) | |
| tree | 0ce25f93b9d6537f3308120abc338f18cefe1191 /opendc-web/opendc-web-runner | |
| parent | 6c6281716ac5ee644b6abacf5164dc3e27687503 (diff) | |
fix(web/runner): Use correct context ClassLoader for ForkJoinPool
This change updates the OpenDC web runner implementation to use the
correct context ClassLoader for simulation jobs running inside a
ForkJoinPool. By default, the ForkJoinPool will use the system class
loader which does not have access to the services needed by the web
runner.
Diffstat (limited to 'opendc-web/opendc-web-runner')
| -rw-r--r-- | opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt b/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt index 9c9a866d..ccc7f03a 100644 --- a/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt +++ b/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/OpenDCRunner.kt @@ -45,6 +45,7 @@ import java.io.File import java.time.Duration import java.util.* import java.util.concurrent.* +import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory /** * Class to execute the pending jobs via the OpenDC web API. @@ -81,7 +82,7 @@ public class OpenDCRunner( /** * The [ForkJoinPool] that is used to execute the simulation jobs. */ - private val pool = ForkJoinPool(parallelism) + private val pool = ForkJoinPool(parallelism, RunnerThreadFactory(Thread.currentThread().contextClassLoader), null, false) /** * A [ScheduledExecutorService] to manage the heartbeat of simulation jobs as well as tracking the deadline of @@ -303,4 +304,15 @@ public class OpenDCRunner( override fun toString(): String = "WebRunnerTopologyFactory" } } + + /** + * A custom [ForkJoinWorkerThreadFactory] that uses the [ClassLoader] of specified by the runner. + */ + private class RunnerThreadFactory(private val classLoader: ClassLoader) : ForkJoinWorkerThreadFactory { + override fun newThread(pool: ForkJoinPool): ForkJoinWorkerThread = object : ForkJoinWorkerThread(pool) { + init { + contextClassLoader = classLoader + } + } + } } |
