From 8594f5a1aa9351e733479c674ddf6dda5bce7f2d Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Mon, 16 Dec 2024 20:24:13 -0500 Subject: [PATCH] [WFLY-7100] Use a concurrent set for ModuleSpecification.userDependenciesSet --- .../deployment/module/ModuleSpecification.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/org/jboss/as/server/deployment/module/ModuleSpecification.java b/server/src/main/java/org/jboss/as/server/deployment/module/ModuleSpecification.java index 6ae0f0782db..1f3542a4af6 100644 --- a/server/src/main/java/org/jboss/as/server/deployment/module/ModuleSpecification.java +++ b/server/src/main/java/org/jboss/as/server/deployment/module/ModuleSpecification.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -57,7 +58,7 @@ public class ModuleSpecification extends SimpleAttachable { *

* User dependencies are not affected by exclusions. */ - private final Set userDependenciesSet = new HashSet<>(); + private final Set userDependenciesSet = new CopyOnWriteArraySet<>(); private final List resourceLoaders = new ArrayList<>(); @@ -163,13 +164,19 @@ public void addUserDependencies(final Collection dependencies) */ public void removeUserDependencies(final Predicate predicate) { Iterator iter = userDependenciesSet.iterator(); - while (iter.hasNext()) { - ModuleDependency md = iter.next(); + Set toRemove = null; + for (ModuleDependency md : userDependenciesSet) { if (predicate.test(md)) { - iter.remove(); - resetDependencyLists(); + if (toRemove == null) { + toRemove = new HashSet<>(); + } + toRemove.add(md); } } + if (toRemove != null) { + userDependenciesSet.removeAll(toRemove); + resetDependencyLists(); + } } public void addLocalDependency(final ModuleDependency dependency) {