Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Need recommendation] Do a repetitive task daily

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may wish to peruse the Using the Timer and TimerTask Classes lesson of Sun's Java Tutorial.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 23
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Use schedule method of Timer class.
    For (e.g)
    Timer timer = new Timer();
    timer.schedule(new TimerTask());
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic