fm134
asked on
how to run java code every day automaticly??
I have a java code and I want it to be run every day automaticly??
what I shout write in the code???
what I shout write in the code???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The above timer.schedule will set up a timer that schedules to call your YourTimerTask.run() once a day.
ASKER
hi pkwan ,
where i put this part
java.util.Timer t = new java.util.Timer();
timer.schedule(new YourTimerTask(), 0, 1000 * 60 * 60 * 24);
// the second parameter is the delay before the first time that runs the code (in millisecond)
// the last parameter is one day in millisecond
where i put this part
java.util.Timer t = new java.util.Timer();
timer.schedule(new YourTimerTask(), 0, 1000 * 60 * 60 * 24);
// the second parameter is the delay before the first time that runs the code (in millisecond)
// the last parameter is one day in millisecond
You should put it inside the init() of your servlet class (if you are using servlet) or the main method of your class (if you are using stand-alone application)
ASKER
so only I have to run tis code once and it will work every day??
java.util.Timer t = new java.util.Timer();
timer.schedule(new YourTimerTask(), 0, 1000 * 60 * 60 * 24);
// the second parameter is the delay before the first time that runs the code (in millisecond)
// the last parameter is one day in millisecond
class YourTimerTask extends TimerTask {
public void run() {
// code that you want to run evey day
}
}