?
Solved

schedule a job

Posted on 2006-06-12
11
Medium Priority
?
239 Views
Last Modified: 2011-09-20
in a web application, I need call a method in a certain period, for example, I need run a method every 10 mins, how to do it?

thanks
0
Comment
Question by:keepworking
[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
  • 2
  • +2
11 Comments
 
LVL 92

Accepted Solution

by:
objects earned 256 total points
ID: 16890555
quartz handles that type of task well

http://sourceforge.net/projects/quartz
0
 
LVL 5

Expert Comment

by:tbboyett
ID: 16890596
You could create a timer similar to the one found on this page:
http://www.javakb.com/Uwe/Forum.aspx/java-programmer/4638/Java-Timer
0
 

Author Comment

by:keepworking
ID: 16890604
can I code a method to run a shceduled job, instead of your reply above?

thanks
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:keepworking
ID: 16890608
CRON???
0
 
LVL 5

Assisted Solution

by:tbboyett
tbboyett earned 248 total points
ID: 16890638
I believe you can use a thread, something like this:

public class TimerThread extends Thread{

    public void run() {
        while (true) {
            try {
                // call some method
            }
            catch (Exception e) {
                // Do something with the exception
            }

            try {
                sleep(5000); // I forget but I think it's like 1000 per second if so 10mins would be like 600000
            } catch (InterruptedException ex) {
               // Do something with the exception
            }
        }
    }
}


// Start it like this
 TimerThread timer = new TimerThread();
 timer.start();
0
 
LVL 92

Expert Comment

by:objects
ID: 16890658
for a simple implementation you could use a Timer

http://javaalmanac.com/egs/java.util/ScheduleRepeat.html

Have a servlet start the timer on startup
0
 

Author Comment

by:keepworking
ID: 16890897
ok, I will try to use a timer and reply soon

thanks
0
 
LVL 13

Assisted Solution

by:kawas
kawas earned 248 total points
ID: 16891670
I have a task that runs every hour,

this is my inner class in a servlet


private class Schedular extends TimerTask {

            public void run() {
                  // do your stuff here
                  
            }

      }

then on initialization, the servlet does the following:

Timer timer = new Timer();
timer.scheduleAtFixedRate(new Schedular(), new java.util.Date(), 1000 * 60 * 60); // run every 60 minutes starting now

// from api:
scheduleAtFixedRate(TimerTask task, Date firstTime, long period)
          Schedules the specified task for repeated fixed-rate execution, beginning at the specified time
0
 
LVL 8

Assisted Solution

by:colr__
colr__ earned 248 total points
ID: 16892242
Another option would be to simplyuse your Operating System schedular to run your 'single execution' java program every now and again.

colr__
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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 Month9 days, 23 hours left to enroll

762 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