Link to home
Start Free TrialLog in
Avatar of fm134
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???
ASKER CERTIFIED SOLUTION
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fm134
fm134

ASKER

tanks pkwan;
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
      }
}

The above timer.schedule will set up a timer that schedules to call your YourTimerTask.run() once a day.
Avatar of fm134

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
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)