• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Chron jobs?

 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm running tomcat 4.x inprocess on top of IIS 5.0 - I'd like to run a certain java program at a scheduled time/intervals, how would I go about doing this?
The only thing I can think of right now is to create a batch file for Windows Task Scheduler to run, but there has to be a better/cleaner way to do so.
 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what about a thread with while(true) loop
which spends most of the time in Thread.sleep mode
and wakes up to do its job once in a while?
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May I ask why you mentioned Tomcat and IIS?
If all you want to do is run a Java program from start to finish, then wait a while, then run it again (and so on), using a batch file invoked by the OS scheduler seems a reasonable approach. If you build your program as an executable jar file you could probably get away without the batch file, if that helps to make it simpler.
Or do you mean that you want to run some code which is already available as a servlet or JSP (or whatever), and need to request a certain URL from time to time?
Please explain a little more for us. Thanks.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Windows Task Scheduler is the cron of Windows so why not use it?
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the server was mine I would use the windows task scheduler. I only really have access to the files via ftp, so anything that I can take care of on my own strictly by files would be a plus. Actually, I kinda have a server-side rep I can talk to that might be able to do the task scheduler for me, but the less I have to involve him, the better. All I need to do is just run a scheduled java program. But if I can't find a suitable solution, I will just make a hidden URL or something and personally trigger it manually at a certain time every day, though that will get annoying pretty fast
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can certainly have a servlet that starts a Thread which sleeps for long periods - when it wakes up it checks the time and runs your job. The servlet could hang on to status information etc. so you could inquire as to how recent runs went.
Bill
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm the thread sleep idea sounds alright.
I already have a "startup" servlet that I use to init some initialial values, I suppose I could call the chron thread and have it go into an endless loop from there. Are there any drawbacks to this method as compared to windows task scheduler?
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there any drawbacks to this method as compared to windows task scheduler?
Mainly that it will only run when your server is running, but pretty much any Java solution will have that drawback.
Don't dismiss the "hidden URL" approach so easily, though. Remember that you can easily set any machine on which you do have control of a scheduler of some sort to fetch your "trigger" URL whenever you want. Ans the ability to manually (and remotely) trigger such behavior if you want to can be invaluable in testing.
 
reply
    Bookmark Topic Watch Topic
  • New Topic