This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes [Need recommendation] Do a repetitive task daily Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "[Need recommendation] Do a repetitive task daily" Watch "[Need recommendation] Do a repetitive task daily" New topic
Author

[Need recommendation] Do a repetitive task daily

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

The daily task needs to be executed
every 12:01 am (one minute past midnight).
This task actually does some initialization
in a database.
Possible solutions:-
1) A thread started from a dummy servlet.
2) Use some database dependent feature and
implement it as a stored proc and schedule
it within the database engine.
I am using IBM WebSphere for deployment of my webapp.
Thanks.
Pho


Regards,

Pho
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
If you implement it in java you'll have a lot more control over the task. You may be limited in what you can do with the database tools.


Rob
SCJP 1.4
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You may wish to peruse the Using the Timer and TimerTask Classes lesson of Sun's Java Tutorial.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

Thanks Rob & Dirk for contributing.
Unfortunately there's no Timer or TimerTask
class in my IDE (IBM Visual Age). Would you
believe that ?
Anyway I'm going to write my own thread
that will calculate the duration to midnight
and sleep till midnight. I don't have a need
for absolute precision in terms of the having
my task execute at exact hour.
Cheers
Pho
[ May 16, 2002: Message edited by: Pho Tek ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
The classes java.util.Timer and java.util.TimerTask are "since 1.3". Perhaps you could easily update the API that your IDE is using. Otherwise, you may have javax.swing.Timer available.
If you'd like a peek at what Sun did in these classes, I've made the source files available:
  • Timer.java
  • TimerTask.java
  • Good Luck.
    Rajasekaran Anand
    Greenhorn

    Joined: Sep 13, 2001
    Posts: 23
    Use schedule method of Timer class.
    For (e.g)
    Timer timer = new Timer();
    timer.schedule(new TimerTask());
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: [Need recommendation] Do a repetitive task daily
     
    Similar Threads
    Need a program in timer schedule..
    Possible reasons?
    Scheduling Pls Help
    TimerTask and servlet container
    need help for timer task