简体   繁体   中英

Java/Database project automation

I have a Java/Database project in Netbeans that I would like to run once a day at a set time. I am using Derby for the database driver. I am trying to automate a process.

  1. How can I 'schedule' this program to run at specified times?
  2. How can I customize this to keep running until a certain criteria is met?

Say my criteria is that It has to populate 500 rows in the database. (So say at the scheduled time it runs it can only populate 400 rows, then maybe 2 hours later it tries running again to fill the last 100 rows)

  1. Lastly, what are the best practices of automation and scheduled tasks?

How can I 'schedule' this program to run at specified times?

This can be done one of two ways, depending on your operating system - write a job that kicks off the java program at the intervals you need. You may then hook up the job to be started off on start up.

In Linux you can accomplish this with a cron job or so. On windows you may refer to this http://support.microsoft.com/kb/308569 .

You may also program the scheduler into your java program using http://quartz-scheduler.org or http://www.sauronsoftware.it/projects/cron4j/ .

How can I customize this to keep running until a certain criteria is met?

This is perhaps best established from within your program, although it is hard to give you directions without much info.

Lastly, what are the best practices of automation and scheduled tasks?

Depending on your application architecture, scheduling and automation can be handled either from within the app or get support from the operating system. The criteria depends on how much control the application needs, which platform makes scheduling easy etc.

Hope this helps.

Quartz is a scheduling project for Java. I have used it in many projects and find it to be very intuitive.

It may be a little over the top for what your after but worth a look anyway.

您可以使用Timer来调度事件,并且必须使用TimerTask实现事件/任务

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM