Running two or more `jlink` invocations concurrently in the same JVM through the `ToolProvider` API causes the simultaneous `run` calls to interfere with one another, even when each invocation targets a distinct `--output` directory and the invocations share no inputs. They may fail with errors such as:
Error: java.lang.IllegalStateException: stream has already been operated upon or closed Error: Resource XYZ already present The problem is that Main.run(...) correctly creates a new `JlinkTask` for each call, but `JlinkTask` defeats this isolation by sharing static `TaskHelper` and `OptionsHelper` instances. Concurrent invocations can therefore overwrite one another’s parsed options and plugin pipelines. The proposed solution is to make `taskHelper` and `optionsHelper` instance fields of `JlinkTask`. This preserves actual concurrency. Synchronizing the provider would unnecessarily serialize image creation and would not protect separate provider instances or direct calls to `Main.run(...)`. --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - 8390505: jlink is not thread safe when used via ToolProvider API Changes: https://git.openjdk.org/jdk/pull/32469/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=32469&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8390505 Stats: 61 lines in 2 files changed: 45 ins; 0 del; 16 mod Patch: https://git.openjdk.org/jdk/pull/32469.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/32469/head:pull/32469 PR: https://git.openjdk.org/jdk/pull/32469
