Search code examples
javajdbcautomationscheduled-tasksderby

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?

Solution

  • 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.