Minor change to the modulo task

This commit is contained in:
Olof Larsson 2013-04-24 09:00:05 +02:00
parent 2db041fea4
commit 18bb47007e
2 changed files with 19 additions and 8 deletions

View File

@ -23,6 +23,15 @@ public abstract class ModuloRepeatTask implements Runnable
public long getPreviousMillis() { return this.previousMillis; }
public void setPreviousMillis(long previousMillis) { this.previousMillis = previousMillis; }
// -------------------------------------------- //
// INVOCATION NUMBER CALCULATION
// -------------------------------------------- //
public long getInvocation(long now)
{
return now / this.getDelayMillis();
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
@ -50,15 +59,17 @@ public abstract class ModuloRepeatTask implements Runnable
@Override
public void run()
{
long now = System.currentTimeMillis();
long nowInvocationNumber = now / this.getDelayMillis();
long previousInvocationNumber = this.getPreviousMillis() / this.getDelayMillis();
long nowMillis = System.currentTimeMillis();
long previousMillis = this.getPreviousMillis();
if (nowInvocationNumber == previousInvocationNumber) return;
long currentInvocation = this.getInvocation(nowMillis);
long previousInvocation = this.getInvocation(previousMillis);
this.invoke();
if (currentInvocation == previousInvocation) return;
this.setPreviousMillis(now);
this.invoke(nowMillis);
this.setPreviousMillis(nowMillis);
}
// -------------------------------------------- //
@ -74,6 +85,6 @@ public abstract class ModuloRepeatTask implements Runnable
// ABSTRACT
// -------------------------------------------- //
public abstract void invoke();
public abstract void invoke(long now);
}

View File

@ -77,8 +77,8 @@ public abstract class Colls<C extends Coll<E>, E>
if (ret == null)
{
ret = this.createColl(collname);
ret.init();
this.name2coll.put(collname, ret);
ret.init();
}
return ret;
}