• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 570
  • Last Modified:

Concurrent modification exception

Hi Experts,

I am getting the following error messages sometime in the following code.  The code is only executed from one thread.  Documents say that I can still get this exception withing one thread.  How can I fix it?  Other than having the method as synchronized?    The rest of the code gets into a deadlock when I have this method as synchronized?




TnsJavaServer.handleEvent(): Caught exception: java.util.ConcurrentModificationException
   
Here is the relevant code snippet.

private HashMap<Integer, ArrayList<TnsEventHandlerInt>> m_ViewMonitorMap;



public  void handleEvent( String msg ) {
....

 try {  
            List eventHandlerList = m_ViewMonitorMap.get(new Integer(rec.getViewId()));
            if(eventHandlerList != null) {
                Iterator it = eventHandlerList.iterator();
                while(it.hasNext()) {
                    TnsEventHandlerInt eventHandler = (TnsEventHandlerInt) it.next();
                    eventHandler.handleTnsEvent(rec);
                }
            }
        } catch(Exception e) {
            MiSystem.logError(MiSystem.SYSTEM_SOFTWARE_LOG, getClass(), fName,
                    "Caught exception: " + e.toString());
        }

}
0
ambuli
Asked:
ambuli
2 Solutions
 
objectsCommented:
are you sure another thread isn't accessing the list?

can u post a stack trace for the exception

e.printStackTrace();
0
 
ksivananthCommented:
>>The code is only executed from one thread.

Might be right for this block but the arralists inside the hashmap may be accessed by other threads!

why don't you iterate through list instance( eventHandlerList ) itself instead of getting the iterator...?

for e.g.,

for( TnsEventHandlerInt eventHandler : eventHandlerList ){
  eventHandler.handleTnsEvent(rec);

}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now