Hi,
I want to schedule a task which will be executed say every day or weekly.I have used struts2 action class in which i am doing all required tasks which include some database activities. I am using hibernate for database actions.
I am using Timer and TimerTask to schedule this task. But i am not able to call the action class from run method of the TimerTask.Does anyone have any idea regarding how to do this?
For example
/*Action class that will start the schedular*/
StartSchedular.java
public class Scheduler extends ActionSupport implements SessionAware
{
@Override
public String execute() throws Exception
{
TimerTask task = new foo(ac,request,response);
Calendar date = Calendar.getInstance();
Timer timer = new Timer();
timer.schedule(task ,5*1000,24*60*60*1000 );
return SUCCESS;
}
}
/*Scheduler class which will schedule the above action class to execute at specified time*/
class schedular extends TimerTask
{
public void run()
{
}
}
/*Scheduler class which will schedule the above action class to execute at specified time*/
class schedular extends TimerTask
{
public void run()
{
}
}
/*Action class that will be executed at scheduled time*/
foo.java
class foo extends ActionSupport implements sessionAware
{
/*
Logic goes here
*/
}
I want to call foo.java from run method. Can anyone help me please.
Reply With Quote