Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Concurrent Modification Exception "

 
Ravi Vanamala
Greenhorn
Posts: 16
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am getting the "ConcurrentModificationException" in call center while callestablished...exception shown as below.

============================================================

2005-03-18 04:21:25,203 -0600 ERROR [ApplicationServiceManager$ServerMessageHandler] - handle(CallEstablishedEvent) Exception: java.util.ConcurrentModificationException
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry()Ljava.util.HashMap$Entry;(Optimized Method)
at java.util.HashMap$EntryIterator.next()Ljava.lang.Object;(Optimized Method)
at com.rockwell.firstpoint.uwa.urlmapping.URLMappingManager.mapToURL(Lcom.rockwell.firstpoint.uwa.xmlMessaging.CallEstablishedEvent Ljava.lang.String;(Optimized Method)
at com.rockwell.firstpoint.uwa.service.manager.ApplicationServiceManager$ServerMessageHandler.handle(Lcom.rockwell.firstpoint.uwa.xmlMessaging.CallEstablishedEvent V(Optimized Method)
at com.rockwell.firstpoint.uwa.xmlMessaging.dispatcher.CallEstablishedEventDispatcher.dispatch(Ljava.lang.Object;Lcom.rockwell.firstpoint.uwa.xmlMessaging.IUWAMessageHandler V(Optimized Method)
at com.rockwell.firstpoint.uwa.xmlMessaging.dispatcher.XMLMessageDispatcher.dispatch(Lcom.rockwell.firstpoint.uwa.xmlMessaging.UWAMessage;Lcom.rockwell.firstpoint.uwa.xmlMessaging.IUWAMessageHandler V(Optimized Method)
at com.rockwell.firstpoint.uwa.service.manager.ApplicationServiceManager$ServerMessageHandler.run()V(ApplicationServiceManager.java:652)
at java.lang.Thread.run()V(Unknown Source)
at java.lang.Thread.startThreadFromVM(Ljava.lang.Thread V(Unknown Source)
2005-03-18 06:12:17,343 -0600 ERROR [Console] - Failed to queue message com.rockwell.firstpoint.uwa.xmlMessaging.DisplayEvent, queue depth = 30, queue capacity = 30
2005-03-18 06:12:17,593 -0600 ERROR [Console] - Failed to queue message com.rockwell.firstpoint.uwa.xmlMessaging.CallEstablishedEvent, queue depth = 30, queue capacity = 30
2005-03-18 06:12:17,843 -0600 ERROR [Console] - Failed to queue message com.rockwell.firstpoint.uwa.xmlMessaging.DisplayEvent, queue depth = 30, queue capacity = 30
2005-03-18 06:12:18,093 -0600 ERROR [Console] - Failed to queue message com.rockwell.firstpoint.uwa.xmlMessaging.LampEvent, queue depth = 30, queue capacity = 30
2005-03-18 06:12:18,343 -0600 ERROR [Console] - Failed to queue message com.rockwell.firstpoint.uwa.xmlMessaging.DisplayEvent, queue depth = 30, queue capacity = 30
2005-03-18 10:06:25,500 -0600 ERROR [BroadcastMessageProvider] - error refreshing the cache at 20050318160525+0000 due to com.rockwell.firstpoint.uwa.database.dao.DataAccessException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(Ljava.io.InputStream;[BII)I(MysqlIO.java:1845)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(Lcom.mysql.jdbc.Buffer Lcom.mysql.jdbc.Buffer;(MysqlIO.java:2292)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(I)Lcom.mysql.jdbc.Buffer;(MysqlIO.java:2788)
at com.mysql.jdbc.MysqlIO.sendCommand(ILjava.lang.String;Lcom.mysql.jdbc.Buffer;ZLjava.lang.String Lcom.mysql.jdbc.Buffer;(MysqlIO.java:1534)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Lcom.mysql.jdbc.Statement;Ljava.lang.String;Ljava.lang.String;Lcom.mysql.jdbc.Buffer;ILcom.mysql.jdbc.Connection;IIZLjava.lang.String;Z)Lcom.mysql.jdbc.ResultSet;(MysqlIO.java:1625)
at com.mysql.jdbc.Connection.execSQL(Lcom.mysql.jdbc.Statement;Ljava.lang.String;ILcom.mysql.jdbc.Buffer;IIZZLjava.lang.String;ZB)Lcom.mysql.jdbc.ResultSet;(Connection.java:2291)
at com.mysql.jdbc.Connection.execSQL(Lcom.mysql.jdbc.Statement;Ljava.lang.String;ILcom.mysql.jdbc.Buffer;IIZZLjava.lang.String;Z)Lcom.mysql.jdbc.ResultSet;(Connection.java:2226)
at com.mysql.jdbc.Statement.executeQuery(Ljava.lang.String Ljava.sql.ResultSet;(Statement.java:1159)
at com.rockwell.firstpoint.uwa.database.dao.MySqlBroadcastMessageDAO.getAllMsgIds()Ljava.util.Vector;(MySqlBroadcastMessageDAO.java:667)
at com.rockwell.firstpoint.uwa.service.provider.BroadcastMessageProvider$MessageCache.removeDeletedMsgIds()V(BroadcastMessageProvider.java:748)
at com.rockwell.firstpoint.uwa.service.provider.BroadcastMessageProvider$MessageCache.run()V(Optimized Method)
at EDU.oswego.cs.dl.util.concurrent.ClockDaemon$RunLoop.run()V(ClockDaemon.java:364)
at java.lang.Thread.run()V(Unknown Source)
at java.lang.Thread.startThreadFromVM(Ljava.lang.Thread V(Unknown Source)


** END NESTED EXCEPTION **


2005-03-18 10:06:25,500 -0600 ERROR [SystemStatusManager] - Database is not available

===========================================================

for the part of the below "ApplicationServiceManager" class code

############################################################

public void handle(CallEstablishedEvent callEstablishedEvent) throws MessageHandlerException {
try {
agentManager.handleMessage(callEstablishedEvent);
callManager.handleMessage(callEstablishedEvent);
statusManager.incrementCallCounter();

/* Attach custom properties if they exist */
String callId = callEstablishedEvent.getCallId();
CustomProperty[] props = callManager.getCustomProperties(callId);
if (props != null && props.length > 0) {
if (serverLog.isDebugEnabled()) {
serverLog.debug("Call(" + callEstablishedEvent.getCallId() + ") attaching " + props.length + " customProperties");
}
callEstablishedEvent.setCustomProperty(props);
}

/*
* Map the call established to a URL for screen-pop
*/
try {
String mappedURL = urlMappingManager.mapToURL(callEstablishedEvent);
if (serverTrace.isDebugEnabled()) {
logTraceServer("handle(CallEstablishedEvent) mapped to URL: " + mappedURL);
}
} catch (NullPointerException e1) {
serverLog.error("handle(CallEstablishedEvent) mapToURL Failed: " + e1, e1);
}

/* send the call established to the user */
sendMessageToClient(callEstablishedEvent);
} catch (Exception e) {
serverLog.error("handle(CallEstablishedEvent) Exception: " + e, e);
}
}

###########################################################

please give me some solution or suggest me how n why its happend somewhat clearly as soon as possible...... in an advanced Thanks if anybody gives the solution.

Regards,
Ravi Babu
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi,
I hope I am not telling you things you already know, but here goes, anyway:

According to the stack trace you have posted, and the error message you say you are getting, it seems you are modifying a "HashMap" while iterating through it.

Since this does not appear to be happening in the code you have posted, I feel that maybe it is a multi-threading problem. In other words, one thread is modifying the "HashMap" while another thread is iterating through it. Could this be the case?

Good Luck,
Avi.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should be like that, indeed. As HashMap is not synchronized.

If the map is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. (For more read the docs.)

You can explicitly synchronized it like below



Moreover, the HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. Again read the docs, there is no other better substitute.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic