camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sven Zethelius <>
Subject RE: synchronization issue
Date Tue, 01 Nov 2011 20:43:06 GMT
Synchronized doesn't save you from ConcurrentModificationException.  CME happens when you are
iterating and the list changes from when the list was first created, even from the same thread.
 For example if someone does myList.add while you are in the for loop, it would trigger the

Given that you are using streaming, I'm assuming the list given to you is already thread safe
(don't know the camel specifics), but it's being dynamically added to as new content comes
in.  The only good way to consume such list is to either do list.remove instead of iterating,
or using list.get(index) instead of the iterator.

-----Original Message-----
From: ebinsingh [] 
Sent: Tuesday, November 01, 2011 1:25 PM
Subject: synchronization issue


I have a wierd situation.
The method is syncronized and the List is also Syncronized, but I get a
ConcurrentModificationException exception.

Appreciate your help.

Thanks & regards,

Camel Route:
	        .log("Starting to process big file: ${header.CamelFileName}")
	        .aggregate(header("CamelFileName"), new

ListParser class:

The line 16 in the below error log is in *Bold*
	public synchronized StringBuilder parseList(List<String> myList) {
		List<String> syncList = Collections.synchronizedList(myList);"Size of MyList : "+syncList.size());
		StringBuilder result = new StringBuilder();
			*for(String in_str: syncList){*			
		}catch(Exception ex){
			logger.error("Error parsing List",ex);
		return result;

For some reason I get the below error 

2011-11-01 16:17:13,220 DEBUG [pool-2-thread-1] aggregate.AggregateProcessor
- Processing aggregated exchange: [FAILED toString()]
2011-11-01 16:17:13,221 INFO  [pool-2-thread-1] impl.DefaultCamelContext -
JMX enabled. Using ManagedManagementStrategy.
2011-11-01 16:17:13,222 DEBUG [pool-2-thread-1]
management.DefaultManagementAgent - Starting JMX agent on server:
2011-11-01 16:17:13,223 INFO  [pool-2-thread-1] camel.VolteListParser - Size
of MyList : 2024
2011-11-01 16:17:13,223 ERROR [pool-2-thread-1] camel.VolteListParser -
Error parsing List
	at java.util.AbstractList$Itr.checkForComodification(
	at java.util.AbstractList$

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message