Sho SHIMIZU
Committed by Thomas Vachuska

Read the latest value of lastSink

Multiple threads could access the field, lastSink, then they should read
the latest value of lastSink

Change-Id: I279ed6fa3db357008603cde5cb2c57671e66b33c
...@@ -69,7 +69,7 @@ public class CoreEventDispatcher extends DefaultEventSinkRegistry ...@@ -69,7 +69,7 @@ public class CoreEventDispatcher extends DefaultEventSinkRegistry
69 69
70 // Means to detect long-running sinks 70 // Means to detect long-running sinks
71 private TimerTask watchdog; 71 private TimerTask watchdog;
72 - private EventSink lastSink; 72 + private volatile EventSink lastSink;
73 private final AtomicLong lastStart = new AtomicLong(0); 73 private final AtomicLong lastStart = new AtomicLong(0);
74 private volatile Future<?> dispatchFuture; 74 private volatile Future<?> dispatchFuture;
75 75
...@@ -164,11 +164,12 @@ public class CoreEventDispatcher extends DefaultEventSinkRegistry ...@@ -164,11 +164,12 @@ public class CoreEventDispatcher extends DefaultEventSinkRegistry
164 long delta = System.currentTimeMillis() - lastStartLocal; 164 long delta = System.currentTimeMillis() - lastStartLocal;
165 if (lastStartLocal > 0 && delta > maxProcessMillis) { 165 if (lastStartLocal > 0 && delta > maxProcessMillis) {
166 lastStart.set(0); 166 lastStart.set(0);
167 + EventSink lastSinkLocal = lastSink;
167 log.warn("Event sink {} exceeded execution time limit: {} ms; spawning new dispatch loop", 168 log.warn("Event sink {} exceeded execution time limit: {} ms; spawning new dispatch loop",
168 - lastSink.getClass().getName(), delta); 169 + lastSinkLocal.getClass().getName(), delta);
169 170
170 // Notify the sink that it has exceeded its time limit. 171 // Notify the sink that it has exceeded its time limit.
171 - lastSink.onProcessLimit(); 172 + lastSinkLocal.onProcessLimit();
172 173
173 // Cancel the old dispatch loop and submit a new one. 174 // Cancel the old dispatch loop and submit a new one.
174 dispatchLoop.stop(); 175 dispatchLoop.stop();
......