1 5 package org.exoplatform.services.task; 6 7 12 abstract public class PeriodicTask extends BaseTask { 13 private long period_ ; 14 private long nextExecutionTime_ ; 15 16 public PeriodicTask(long period) { 17 period_ = period ; 18 nextExecutionTime_ = System.currentTimeMillis() + period ; 19 } 20 21 final public void execute() throws Exception { 22 long currentTime = System.currentTimeMillis() ; 23 if(currentTime > nextExecutionTime_) { 24 try { 25 run() ; 26 } finally { 27 nextExecutionTime_ = System.currentTimeMillis() + period_ ; 28 } 29 } 30 } 31 32 abstract public void run() throws Exception ; 33 } 34 | Popular Tags |