I need to run a Java 开发者_StackOverflowprogram periodically say once ever 2 hours. How do I do this in Linux(Ubuntu)?
You should add an entry to crontab:
0 */2 * * * script.sh
In script.sh you should have something like:
#! /bin/sh
java -jar <your jar file>
how about a cron-job ?
Cron is a system daemon used to execute desired tasks (in the background) at designated times.
More information can be found by typing in Ubuntu:
man crontab
or here
Use cron.
https://help.ubuntu.com/community/CronHowto
Use a cronjob.
Cron: http://en.wikipedia.org/wiki/Cron
Will let you launch your Java task at a set interval.
For a nice interface to cron you can use:
sudo apt-get install gnome-schedule
A pure Java solution would use Quartz. That'll work on any operating system. It'll have the added advantage of allowing you to send alert e-mails if an exception is caught. It'll fit nicely into your logging/monitoring framework.
精彩评论