Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

schedule a job

Posted on 2006-06-12
11
Medium Priority
?
240 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

618 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