diff --git a/core/java/src/net/i2p/util/SimpleTimer2.java b/core/java/src/net/i2p/util/SimpleTimer2.java index 4cfab3a0a92f191a84871c358d403f96f6bc1b33..e8dcc2fcbe8c03da0094fc0348edb056d71c5347 100644 --- a/core/java/src/net/i2p/util/SimpleTimer2.java +++ b/core/java/src/net/i2p/util/SimpleTimer2.java @@ -416,13 +416,15 @@ public class SimpleTimer2 { case IDLE: // fall through case RUNNING: throw new IllegalStateException(this + " not possible to be in " + _state); - case SCHEDULED: // proceed, switch to IDLE in case I need to reschedule - _state = TimedEventState.IDLE; + case SCHEDULED: + // proceed, will switch to IDLE to reschedule } // if I was rescheduled by the user, re-submit myself to the executor. - int difference = (int)(_nextRun - before); // careful with long uptimes + long difference = _nextRun - before; // careful with long uptimes if (difference > _fuzz) { + // proceed, switch to IDLE to reschedule + _state = TimedEventState.IDLE; schedule(difference); return; } @@ -437,10 +439,12 @@ public class SimpleTimer2 { else if (_log.shouldLog(Log.WARN)) _log.warn(_pool + " no _future " + this); // This can be an incorrect warning especially after a schedule(0) - if (_log.shouldLog(Log.WARN) && delay > 100) - _log.warn(_pool + " early execution " + delay + ": " + this); - else if (_log.shouldLog(Log.WARN) && delay < -1000) - _log.warn(" late execution " + (0 - delay) + ": " + this + _pool.debug()); + if (_log.shouldWarn()) { + if (delay > 100) + _log.warn(_pool + " early execution " + delay + ": " + this); + else if (delay < -1000) + _log.warn(" late execution " + (0 - delay) + ": " + this + _pool.debug()); + } try { timeReached(); } catch (Throwable t) { diff --git a/router/java/src/net/i2p/router/transport/OutboundMessageRegistry.java b/router/java/src/net/i2p/router/transport/OutboundMessageRegistry.java index 7c8e1b37dd6aa9b415fd96cece7a62a0f668fcbe..9c04f52b63e6d2e03892952643de6c289aae0deb 100644 --- a/router/java/src/net/i2p/router/transport/OutboundMessageRegistry.java +++ b/router/java/src/net/i2p/router/transport/OutboundMessageRegistry.java @@ -330,12 +330,14 @@ public class OutboundMessageRegistry { if (r > 0 || e > 0 || a > 0) _log.debug("Expired: " + e + " remaining: " + r + " active: " + a); } - if (_nextExpire <= now) - _nextExpire = now + 10*1000; - schedule(_nextExpire - now); + synchronized(this) { + if (_nextExpire <= now) + _nextExpire = now + 10*1000; + schedule(_nextExpire - now); + } } - public void scheduleExpiration(MessageSelector sel) { + public synchronized void scheduleExpiration(MessageSelector sel) { long now = _context.clock().now(); if ( (_nextExpire <= now) || (sel.getExpiration() < _nextExpire) ) { _nextExpire = sel.getExpiration();