?
Solved

how to run java code every day automaticly??

Posted on 2007-04-09
5
Medium Priority
?
554 Views
Last Modified: 2012-05-05
I have a java code and I want it to be run every day automaticly??
what I shout write in the code???
0
Comment
Question by:fm134
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 2000 total points
ID: 18874919
Two ways:
1. Use the scheduler provided by OS, i.e. Scheduled Task in Windows, cronjob in Unix etc ( applicable for stand-alone application only)
2. Use a Timer like this (stand-alone application/servlet):

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

0
 

Author Comment

by:fm134
ID: 18874937
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
      }
}

0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 18874972
The above timer.schedule will set up a timer that schedules to call your YourTimerTask.run() once a day.
0
 

Author Comment

by:fm134
ID: 18913135
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
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 18913432
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)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question