Minor change to the modulo task
This commit is contained in:
parent
2db041fea4
commit
18bb47007e
@ -23,6 +23,15 @@ public abstract class ModuloRepeatTask implements Runnable
|
|||||||
public long getPreviousMillis() { return this.previousMillis; }
|
public long getPreviousMillis() { return this.previousMillis; }
|
||||||
public void setPreviousMillis(long previousMillis) { this.previousMillis = previousMillis; }
|
public void setPreviousMillis(long previousMillis) { this.previousMillis = previousMillis; }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INVOCATION NUMBER CALCULATION
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public long getInvocation(long now)
|
||||||
|
{
|
||||||
|
return now / this.getDelayMillis();
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -50,15 +59,17 @@ public abstract class ModuloRepeatTask implements Runnable
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
long now = System.currentTimeMillis();
|
long nowMillis = System.currentTimeMillis();
|
||||||
long nowInvocationNumber = now / this.getDelayMillis();
|
long previousMillis = this.getPreviousMillis();
|
||||||
long previousInvocationNumber = this.getPreviousMillis() / this.getDelayMillis();
|
|
||||||
|
|
||||||
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
|
// ABSTRACT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public abstract void invoke();
|
public abstract void invoke(long now);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -77,8 +77,8 @@ public abstract class Colls<C extends Coll<E>, E>
|
|||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
ret = this.createColl(collname);
|
ret = this.createColl(collname);
|
||||||
ret.init();
|
|
||||||
this.name2coll.put(collname, ret);
|
this.name2coll.put(collname, ret);
|
||||||
|
ret.init();
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user