java cron job_Java Cron job to run a jar file

Quartz is good, but often times we just need a simple scheduler system to run a jar file periodically. On *unix system, you can use the build-in cron to schedule a scheduler job easily.

In this example, we will show you how to create a cron job on *nix to run a jar file, by daily and hourly.

1. Create a Cron Job

To create a cron job, in terminal, type crontab -e to edit the cron job. Review following examples :

1.1 Run daily at 00:00, accepts two parameters.

# run everyday

0 0 * * * java -jar /home/mkyong/crawler/webcrawler.jar param1 param2

1.2 Run daily at 02:00 am, pass rir.name as a system property with -D option.

# run everyday at 2am

0 2 * * * java -jar -Drir.name="ripe" /home/mkyong/crawler/whoiscrawler.jar

1.3 Run hourly, assume this jar is logging message with the logback framework.

# run every hour

0 * * * * java -jar -Dlogback.configurationFile=/home/mkyong/logback.xml /home/mkyong/crawler/crawler.jar

Exit, save and override, done.

Display Cron Jobs

To display the existing cron job, type crontab -l

References

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值