Should addRoutes be synchronized?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Should addRoutes be synchronized?

Bob Paulin-2
Hi,

I've recently hit an issue with using DefaultCamelContext addRoutes /
removeRouteDefinitions within a dynamic environment (routes are adding
and removed at runtime).  It seems that the removeRouteDefinitions is
synchronized however the addRoutes is not.  On occasion has produced the
the ConcurrentModificationException [1].  I've solved it in my client
code by surrounding the calls to adding and removing with synchronized
blocks [2], however it might be safer to simply synchronize addRoutes
[3].  Thoughts?


- Bob

[1]

2017-11-02 22:57:12,205 | ERROR | Thread-7         |
Activator                        | 20 -
com.myclient.api.myclient-api-core - 1.0.411 | Error Adding Camel Route
Builder
java.util.ConcurrentModificationException
    at
java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)[:1.8.0_131]
    at java.util.ArrayList$Itr.next(ArrayList.java:851)[:1.8.0_131]
    at
org.apache.camel.builder.RouteBuilder.populateRests(RouteBuilder.java:454)[82:org.apache.camel.camel-core:2.18.4]
    at
org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:330)[82:org.apache.camel.camel-core:2.18.4]
    at
org.apache.camel.impl.DefaultCamelContext$1.call(DefaultCamelContext.java:916)[82:org.apache.camel.camel-core:2.18.4]
    at
org.apache.camel.impl.DefaultCamelContext$1.call(DefaultCamelContext.java:913)[82:org.apache.camel.camel-core:2.18.4]
    at
org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3027)[82:org.apache.camel.camel-core:2.18.4]
    at
org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:913)[82:org.apache.camel.camel-core:2.18.4]
    at
com.myclient.api.internal.Activator.addingService(Activator.java:136)[20:com.myclient.api.myclient-api-core:1.0.411]
    at
com.myclient.api.internal.Activator.addingService(Activator.java:45)[20:com.myclient.api.myclient-api-core:1.0.411]
   ...

[2]

synchronized(camelContext)
 {
                this.camelContext.addRoutes(builder);
 }

[3]

public synchronized void addRoutes(final RoutesBuilder builder) throws
Exception





signature.asc (836 bytes) Download Attachment