On Thu, 20 Aug 2026 13:28:37 GMT, Dušan Bálek <[email protected]> wrote:
> 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). This pull request has now been integrated. Changeset: 6212c807 Author: Dušan Bálek <[email protected]> URL: https://git.openjdk.org/jdk/commit/6212c8075b4791e11c9c27c202e932fa7e0a88ec Stats: 53 lines in 2 files changed: 37 ins; 0 del; 16 mod 8390505: jlink is not thread safe when used via ToolProvider API Reviewed-by: alanb ------------- PR: https://git.openjdk.org/jdk/pull/32469
