• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Execute Java Code at a specific time

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to execute a piece of java code once a week at a specific time. How do I do that ? Can anyone please tell me ?
Thank you.
Cheers,
Sailaja.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by lakshmi Sailaja:
I need to execute a piece of java code once a week at a specific time. How do I do that ? Can anyone please tell me ?


Do you need to execute the piece of code from within a Java application? Or do you need to execute a Java application from your OS?
If it is the latter (execute from OS), you can use NT's at-scheduler (type "help at" from the NT command prompt). If you are running UNIX, I think you can use either "at" or "cron" (type "man at" or "man cron" for more details). The argument to at or cron would be "java MyClass myarg1 myarg2".
If the problem is the former (execute from within Java app), I guess you could have some sort of thread that woke up at specified intervals, executed some code, then went back to sleep. This isn't guaranteed to be very precise, and I'm not entirely sure that it would work. (I am not a threading expert by any means.)
My recommendation would be to use at or cron, and restructure your classes so that there's a main() in a class that you can run from at or cron.
--
Susan
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic