简体   繁体   English

Java /数据库项目自动化

[英]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. 我在Netbeans中有一个Java / Database项目,我希望在设定的时间每天运行一次。 I am using Derby for the database driver. 我正在使用Derby作为数据库驱动程序。 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. 说我的标准是它必须在数据库中填充500行。 (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) (所以说在它运行的预定时间它只能填充400行,然后可能在2小时后它再次尝试运行以填充最后100行)

  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. 这可以通过以下两种方式之一完成,具体取决于您的操作系统 - 编写一个以您需要的间隔启动Java程序的作业。 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. 在Linux中,您可以使用cron作业完成此操作。 On windows you may refer to this http://support.microsoft.com/kb/308569 . 在Windows上,您可以参考此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/ . 您也可以使用http://quartz-scheduler.orghttp://www.sauronsoftware.it/projects/cron4j/将调度程序编程到您的Java程序中。

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. Quartz是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实现事件/任务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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