From 3864a987bbfa1cd4aa0b671fb536e62bd98e1d0b Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 22 Jul 2026 15:03:19 +0000 Subject: [PATCH] Remove unnecessary static synchronization in ToolchainMojo Fixes #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. --- .../org/apache/maven/plugins/toolchain/ToolchainMojo.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java index d8454f6..8944b0b 100644 --- a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java +++ b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java @@ -46,8 +46,6 @@ configurator = "toolchains-requirement-configurator", threadSafe = true) public class ToolchainMojo extends AbstractMojo { - private static final Object LOCK = new Object(); - /** */ @Component @@ -144,9 +142,7 @@ protected boolean selectToolchain(String type, Map params) throw getLog().info("Found matching toolchain for type " + type + ": " + tc); // store matching toolchain to build context - synchronized (LOCK) { - toolchainManagerPrivate.storeToolchainToBuildContext(tc, session); - } + toolchainManagerPrivate.storeToolchainToBuildContext(tc, session); return true; }