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 CME.
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 [mailto:[email protected]] Sent: Tuesday, November 01, 2011 1:25 PM To: [email protected] Subject: synchronization issue Hi, 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, Ebe Camel Route: from("file:/vzwhome/c0sineb/work_dir/camel_proj/data/input?delete=true") //from("file:C:\\camelProject\\data\\inbox?delete=true") .log("Starting to process big file: ${header.CamelFileName}") .split(body().tokenize("\n")).streaming() .aggregate(header("CamelFileName"), new MyListAggregation()).completionSize(2000) .parallelProcessing() .executorService(threadPool) .bean(ListParser.class,"parseList") 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); logger.info("Size of MyList : "+syncList.size()); StringBuilder result = new StringBuilder(); try{ *for(String in_str: syncList){* result.append("&").append(parseString(in_str)); } }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: com.sun.jmx.mbeanserver.JmxMBeanServer@1a1c42f 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 java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372) at java.util.AbstractList$Itr.next(AbstractList.java:343) at com.verizon.learn.camel.VolteListParser.parseVolteList(ListParser.java:16) -- View this message in context: http://camel.465427.n5.nabble.com/synchronization-issue-tp4956228p4956228.html Sent from the Camel - Users mailing list archive at Nabble.com.
