Multiple problems in your code, here are they:
- First of all you have picked a confusing name for your TimerTask child class.
Timer
is the class defined injava.util
package, which is used to create the scheduled task. - You are creating an anonymous class of type TimerTask that will be used to run the scheduled task.
You can try to change your code like this:
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
System.out.println("inside listener context");
Timer timer = new Timer();
Date executionDate = new Date();
long period = 24 * 60 * 60 * 1000;
timer.scheduleAtFixedRate(new MyTimerTask(), executionDate, period);
}
MyTimerTask
package com.uttara.reg;
import java.util.Date;
import java.util.TimerTask;
public class MyTimerTask extends TimerTask {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("inside run of timer");
}
public void scheduleAtFixedRate(TimerTask timerTask, Date executionDate, long period)
{
System.out.println("run");
// TODO Auto-generated method stub
}
}