KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > task > PeriodicTask


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.task;
6
7 /**
8  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
9  * @since Nov 30, 2004
10  * @version $Id$
11  */

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 JavaDoc {
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 JavaDoc ;
33 }
34
Popular Tags