Skip to content

Remove unnecessary static synchronization in ToolchainMojo - #180

Open
elharo wants to merge 1 commit into
apache:masterfrom
elharo:remove-unnecessary-synchronization
Open

Remove unnecessary static synchronization in ToolchainMojo#180
elharo wants to merge 1 commit into
apache:masterfrom
elharo:remove-unnecessary-synchronization

Conversation

@elharo

@elharo elharo commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #174

Problem

The static LOCK object and synchronized block around toolchainManagerPrivate.storeToolchainToBuildContext() are unnecessary:

  1. The plugin is marked threadSafe=true, meaning Maven may execute it concurrently for different modules/sessions
  2. storeToolchainToBuildContext() stores data into the build context, which is already per-session and thread-safe
  3. The static lock introduces unnecessary contention: one module's toolchain selection blocks another unrelated module's selection, defeating the purpose of threadSafe=true

Impact

In multi-module Maven builds where the toolchains plugin runs in multiple modules (e.g., via inherited plugin configuration), the static lock serializes what could otherwise run in parallel, slowing down builds.

Fix

Remove the private static final Object LOCK field and the synchronized (LOCK) block around the storeToolchainToBuildContext call, since it provides no benefit.

Fixes apache#174

The static LOCK object and synchronized block around
toolchainManagerPrivate.storeToolchainToBuildContext() are unnecessary
because:

1. The plugin is marked threadSafe=true, meaning Maven may execute it
   concurrently for different modules/sessions
2. storeToolchainToBuildContext() stores data into the build context,
   which is already per-session and thread-safe
3. The static lock introduces unnecessary contention: one module's
   toolchain selection blocks another unrelated module's selection,
   defeating the purpose of threadSafe=true

In multi-module Maven builds where the toolchains plugin runs in
multiple modules, the static lock serializes what could otherwise run
in parallel, slowing down builds.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes a global static synchronization point in ToolchainMojo that unnecessarily serialized toolchain selection across modules in multi-module builds, undermining the plugin’s threadSafe = true intent and introducing avoidable contention.

Changes:

  • Removed the static LOCK field from ToolchainMojo.
  • Removed the synchronized (LOCK) block and performs storeToolchainToBuildContext(tc, session) directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessary static synchronization in ToolchainMojo causes contention in multi-module builds

2 participants