You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Chris Ribble (JIRA)" <ji...@apache.org> on 2015/10/20 00:16:27 UTC
[jira] [Created] (CAMEL-9237) ConcurrentModificationException when
adding/removing routes in multiple threads
Chris Ribble created CAMEL-9237:
-----------------------------------
Summary: ConcurrentModificationException when adding/removing routes in multiple threads
Key: CAMEL-9237
URL: https://issues.apache.org/jira/browse/CAMEL-9237
Project: Camel
Issue Type: Bug
Components: camel-core
Affects Versions: 2.16.0
Reporter: Chris Ribble
Dynamically adding or removing routes in multiple threads can cause a ConcurrentModificationException. For example, in my project's tests, we dynamically mock out a large number of routes. When we run these tests serially it works fine, but in parallel we almost always see a ConcurrentModificationException when DefaultCamelContext passes the routeDefinitions list to RouteDefinitionHelper.validateUniqueIds
I propose that we fix this by making routeDefinitions (in DefaultCamelContext) a CopyOnWriteArrayList instead of an ArrayList. Apparently this was already done for the lifecycleStrategies list, presumably for the same reason.
It's also curious that the accessors for this list are marked synchronized. Should the reference be volatile instead? Since the accessors aren't mutating the list, the synchronized on the method is only serving as a memory barrier and a superfluous lock on access.
I also think we should consider doing the same for restDefinitions, since there is nothing preventing this list from being modified in multiple threads.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)