Thursday, October 8, 2009

Scheduler using Java

import java.util.Timer;
import java.util.TimerTask;

public class Schedulers extends TimerTask
{

static Timer timer = null;
boolean bInit = false;
private static Schedulers scheduler = null;

protected void init() throws Exception
{
}

void schedule() throws Exception{

System.out.println("Running"+System.currentTimeMillis());

}

public void run()
{
try
{
if (!bInit) init();
schedule();
}
catch (Exception e)
{
e.printStackTrace();
}
}

public static void main(String args[])
{
try{
start(new Schedulers(),1);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void start(Schedulers jscheduler, int min) throws Exception
{
scheduler=jscheduler;
timer = new Timer();
timer.schedule(scheduler, new java.util.Date(), min*60*1000);
}
}