diff options
author | Dor Bivas <dor1_b@walla.com> | 2014-04-15 17:14:48 +0300 |
---|---|---|
committer | Dor Bivas <dor1_b@walla.com> | 2014-04-15 17:19:16 +0300 |
commit | 2df479225932d3e8ee99a601182ed01996a54666 (patch) | |
tree | 565fca2de3b57bb450e82012a1cf2b1c68959079 | |
parent | 8ef488aca25c157ae87efcb10fd96358f93c3db8 (diff) |
server: don't panic on ConcurrentModificationException
If the connections list changes durreng sending of a message, abort the
sending but don't panic further than that.
-rw-r--r-- | src/Server/CommandsTable.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/Server/CommandsTable.java b/src/Server/CommandsTable.java index 25afadf..ba80ade 100644 --- a/src/Server/CommandsTable.java +++ b/src/Server/CommandsTable.java @@ -1,5 +1,6 @@ package Server; import java.io.IOException; +import java.util.ConcurrentModificationException; import java.util.Hashtable; import java.util.Iterator; @@ -98,16 +99,23 @@ class CommandPrivmsg extends Command Iterator<Connection> iter = ChatServer.server.getConnectionIterator(); - while (iter.hasNext()) + try { - Connection con = iter.next(); - - if (client.IfMyCon(con)) + while (iter.hasNext()) { - continue; + Connection con = iter.next(); + + if (client.IfMyCon(con)) + { + continue; + } + ports += con.toString(); + this.printUser(con.getClient(), client, "PRIVMSG " + starr[0] + " :" + line); } - ports += con.toString(); - this.printUser(con.getClient(), client, "PRIVMSG " + starr[0] + " :" + line); + } + catch (java.util.ConcurrentModificationException e) + { + System.err.println("concurrency error, privmsg may not be fully delivered\n"); } System.out.println("printed message to ports: " + ports); } |