aspose file tools*
The moose likes Beginning Java and the fly likes Executing a fn every hour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Executing a fn every hour" Watch "Executing a fn every hour" New topic
Author

Executing a fn every hour

David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
I want to run a java program that calls a function defined in it's class every hour. I've never done such a thing (only META refresh in HTML, hahaha).
Could anyone point me how to do this? I would run the java program from the command line and the logic to do the calling would reside in the main().
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Here's a suggestion:

I would recommend starting a separate thread rather than keeping everything in main().


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
Thanks Marilyn!
Clarification: Is it necessary to call the function before the try {...} block? Is the difference simply:
function() ... 1 hour ... function() versus
...1 hour... function()?
Matt Siegel
Ranch Hand

Joined: Jul 18, 2000
Posts: 55
Check out the java.util.Timer and the corresponding java.util.TimerTask classes. They will do exactly what you want.
HTH,
Matt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Originally posted by David Duran:
Clarification: Is it necessary to call the function before the try {...} block? Is the difference simply:
function() ... 1 hour ... function() versus
...1 hour... function()?

Yes. That's the only difference.
David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
Thanks Matt, the Timer class looks like it would do the job but this code is going into an RMI server app which already extends UnicastRemoteObject. Since Timer requires a TimerTask object as one of the parameters to it's schedule functions that would mean I'd have to extend TimerTask (since it's abstract) within this class.
Since I can't extend 2 classes I guess I can't use TimerTask and Timer (unless I'm mistaken). Right now I'm able to implement threads because I'm implementing Runnable as opposed to extending Thread.
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
hi,
try javax.swing.Timer
it takes an actionListener so no need to extend, jsut implement the interface.
k
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing a fn every hour
 
Similar Threads
Evaluation soft!
Task Scheduler
run a Java application every hour automatically
schedule job in java
file upload