[
https://issues.apache.org/jira/browse/CAMEL-9237?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Chris Ribble updated CAMEL-9237:
--------------------------------
Description:
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.
Since the references are final, there's no reason to use volatile instead, so
it seems like the synchronized here is pointless.
I also think we should consider doing the same for restDefinitions, since there
is nothing preventing this list from being modified in multiple threads.
was:
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.
> 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.
> Since the references are final, there's no reason to use volatile instead, so
> it seems like the synchronized here is pointless.
> 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)