forked from I2P_Developers/i2p.i2p
Timers: Improve OutboundMessageRegistry locking
SimpleTimer2 cleanups possible fix for ticket #1694
This commit is contained in:
@ -416,13 +416,15 @@ public class SimpleTimer2 {
|
|||||||
case IDLE: // fall through
|
case IDLE: // fall through
|
||||||
case RUNNING:
|
case RUNNING:
|
||||||
throw new IllegalStateException(this + " not possible to be in " + _state);
|
throw new IllegalStateException(this + " not possible to be in " + _state);
|
||||||
case SCHEDULED: // proceed, switch to IDLE in case I need to reschedule
|
case SCHEDULED:
|
||||||
_state = TimedEventState.IDLE;
|
// proceed, will switch to IDLE to reschedule
|
||||||
}
|
}
|
||||||
|
|
||||||
// if I was rescheduled by the user, re-submit myself to the executor.
|
// 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) {
|
if (difference > _fuzz) {
|
||||||
|
// proceed, switch to IDLE to reschedule
|
||||||
|
_state = TimedEventState.IDLE;
|
||||||
schedule(difference);
|
schedule(difference);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -437,10 +439,12 @@ public class SimpleTimer2 {
|
|||||||
else if (_log.shouldLog(Log.WARN))
|
else if (_log.shouldLog(Log.WARN))
|
||||||
_log.warn(_pool + " no _future " + this);
|
_log.warn(_pool + " no _future " + this);
|
||||||
// This can be an incorrect warning especially after a schedule(0)
|
// This can be an incorrect warning especially after a schedule(0)
|
||||||
if (_log.shouldLog(Log.WARN) && delay > 100)
|
if (_log.shouldWarn()) {
|
||||||
_log.warn(_pool + " early execution " + delay + ": " + this);
|
if (delay > 100)
|
||||||
else if (_log.shouldLog(Log.WARN) && delay < -1000)
|
_log.warn(_pool + " early execution " + delay + ": " + this);
|
||||||
_log.warn(" late execution " + (0 - delay) + ": " + this + _pool.debug());
|
else if (delay < -1000)
|
||||||
|
_log.warn(" late execution " + (0 - delay) + ": " + this + _pool.debug());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
timeReached();
|
timeReached();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
@ -330,12 +330,14 @@ public class OutboundMessageRegistry {
|
|||||||
if (r > 0 || e > 0 || a > 0)
|
if (r > 0 || e > 0 || a > 0)
|
||||||
_log.debug("Expired: " + e + " remaining: " + r + " active: " + a);
|
_log.debug("Expired: " + e + " remaining: " + r + " active: " + a);
|
||||||
}
|
}
|
||||||
if (_nextExpire <= now)
|
synchronized(this) {
|
||||||
_nextExpire = now + 10*1000;
|
if (_nextExpire <= now)
|
||||||
schedule(_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();
|
long now = _context.clock().now();
|
||||||
if ( (_nextExpire <= now) || (sel.getExpiration() < _nextExpire) ) {
|
if ( (_nextExpire <= now) || (sel.getExpiration() < _nextExpire) ) {
|
||||||
_nextExpire = sel.getExpiration();
|
_nextExpire = sel.getExpiration();
|
||||||
|
Reference in New Issue
Block a user