Skip to content

Instantly share code, notes, and snippets.

@ddv2005
Created January 15, 2013 20:08
Show Gist options
  • Save ddv2005/4541575 to your computer and use it in GitHub Desktop.
Save ddv2005/4541575 to your computer and use it in GitHub Desktop.
handle ConcurrentModification Exception
diff --git a/src/main/java/zmq/PollerBase.java b/src/main/java/zmq/PollerBase.java
index b1ad801..a37ed09 100644
--- a/src/main/java/zmq/PollerBase.java
+++ b/src/main/java/zmq/PollerBase.java
@@ -99,7 +99,7 @@ abstract public class PollerBase {
// Get the current time.
long current = Clock.now_ms ();
- ArrayList <Long> removes = new ArrayList <Long> ();
+ ArrayList <Long> executes = new ArrayList <Long> ();
// Execute the timers that are already due.
long ret = 0L;
for (Entry <Long, TimerInfo> o : timers.entrySet ()) {
@@ -112,14 +112,20 @@ abstract public class PollerBase {
ret = o.getKey() - current;
break;
}
-
- // Trigger the timer.
- o.getValue().sink.timer_event (o.getValue().id);
- // Remove it from the list of active timers.
- removes.add (o.getKey ());
+
+ // Add timer toexecution list
+ executes.add (o.getKey ());
}
- for (long key : removes)
+ for (long key : executes)
+ {
+ TimerInfo ti = timers.get(key);
+ if(ti!=null)
+ {
+ // Trigger the timer.
+ ti.sink.timer_event (ti.id);
+ }
timers.remove (key);
+ }
// There are no more timers.
return ret;
}
@miniway
Copy link

miniway commented Jan 18, 2013

Thank you for addressing the issue.

Please send a pull request regarding this issue.

But please make sure the indentation is 4 spaces (no tabs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment