This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch splituow in repository https://gitbox.apache.org/repos/asf/camel.git
commit f4c05193c62067287287b41cbf77a81893c65fb1 Author: Claus Ibsen <[email protected]> AuthorDate: Mon Oct 13 12:15:55 2025 +0200 CAMEL-22533: ConcurrentModificationException thrown in JMX-enabled application using Split EIP w/ shared UoW. Thanks to Rui Ventura for reporting and the reproducer test case. --- .../camel/impl/engine/DefaultUnitOfWork.java | 4 +- .../issues/SplitParallelSharedUoWIssueTest.java | 54 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultUnitOfWork.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultUnitOfWork.java index dd50277f558c..2c5d1dba6be3 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultUnitOfWork.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultUnitOfWork.java @@ -16,13 +16,13 @@ */ package org.apache.camel.impl.engine; -import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Predicate; @@ -58,7 +58,7 @@ public class DefaultUnitOfWork implements UnitOfWork { final boolean useBreadcrumb; private final CamelContext context; - private final Deque<Route> routes = new ArrayDeque<>(8); + private final Deque<Route> routes = new ConcurrentLinkedDeque<>(); private final Lock lock = new ReentrantLock(); private final Logger log; private Exchange exchange; diff --git a/core/camel-management/src/test/java/org/apache/camel/issues/SplitParallelSharedUoWIssueTest.java b/core/camel-management/src/test/java/org/apache/camel/issues/SplitParallelSharedUoWIssueTest.java new file mode 100644 index 000000000000..52cb7b04418c --- /dev/null +++ b/core/camel-management/src/test/java/org/apache/camel/issues/SplitParallelSharedUoWIssueTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.issues; + +import java.util.stream.Stream; + +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.management.ManagementTestSupport; +import org.junit.jupiter.api.RepeatedTest; + +public class SplitParallelSharedUoWIssueTest extends ManagementTestSupport { + + @RepeatedTest(1000) + public void testSplitParallelShareeUoW() throws Exception { + getMockEndpoint("mock:line").expectedMessageCount(1000); + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.sendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .setBody(constant(Stream.iterate(1, i -> i + 1).limit(1000).toList())) + .split().body().shareUnitOfWork().parallelProcessing() + .log("Number ${body}") + .to("mock:line") + .end() + .log("All done") + .to("mock:result"); + } + }; + } +}
