java JavaQuartz 作业持久化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11186201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:07:59  来源:igfitidea点击:

JavaQuartz Job persistence

javastruts2quartz-scheduler

提问by Sangram Anand

I am not much familiar with Java Quartz, we just used a test job thats scheduled daily. For our Struts2 webapplication, we want to run a few daily jobs that are scheduled at different times of the day. The jobs should be in persistence state such that even if the jobs fails due to server down/application failed, they should re-execute later when server is up. Also can i store the status/results of the jobs in DB, so as to monitor the jobs. Any suggestions would be helpful.

我对 Java Quartz 不太熟悉,我们只是使用了一个每天安排的测试工作。对于我们的 Struts2 web 应用程序,我们希望运行一些在一天中的不同时间安排的日常作业。作业应该处于持久状态,这样即使由于服务器关闭/应用程序失败而导致作业失败,它们也应该在服务器启动后重新执行。我也可以将作业的状态/结果存储在数据库中,以便监控作业。任何的意见都将会有帮助。

-- Thanks

- 谢谢

采纳答案by Umesh Awasthi

Whatever you have mentioned is possible in Quartz scheduler and there is already a feature with triggers which we generally call Misfire Instructionsthis is what doc say about it

你提到的任何事情都可以在 Quartz 调度器中实现,并且已经有一个带有触发器的功能,我们通常称之为Misfire Instructions这就是文档所说的

Another important property of a Trigger is its "misfire instruction". A misfire occurs if a persistent trigger "misses" its firing time because of the scheduler being shutdown, or because there are no available threads in Quartz's thread pool for executing the job. The different trigger types have different misfire instructions available to them. By default they use a 'smart policy' instruction - which has dynamic behavior based on trigger type and configuration. When the scheduler starts, it searches for any persistent triggers that have misfired, and it then updates each of them based on their individually configured misfire instructions. When you start using Quartz in your own projects, you should make yourself familiar with the misfire instructions that are defined on the given trigger types, and explained in their JavaDoc. More specific information about misfire instructions will be given within the tutorial lessons specific to each trigger type.

触发器的另一个重要属性是它的“失火指令”。如果由于调度程序关闭,或者因为 Quartz 的线程池中没有可用的线程来执行作业,持久触发器“错过”了它的触发时间,则会发生失火。不同的触发器类型有不同的失火指令可供它们使用。默认情况下,它们使用“智能策略”指令——它具有基于触发器类型和配置的动态行为。当调度程序启动时,它会搜索任何已失火的持久触发器,然后根据它们单独配置的失火指令更新每个触发器。当你开始在你自己的项目中使用 Quartz 时,你应该让自己熟悉在给定的触发器类型上定义的失火指令,并在他们的 JavaDoc 中进行了解释。有关失火指令的更多具体信息将在针对每种触发器类型的教程课程中提供。

Regarding Job persistence Quartz comes with few build in mechanism and all you need to set JobStore as JDBCJobStore

关于作业持久性 Quartz 自带的内置机制很少,您只需将 JobStore 设置为 JDBCJobStore

I suggest you to go with Quartz scheduler documentits quite easy and have lots of tutorial and examples to start with.

我建议你使用Quartz 调度器文档,它非常简单,并且有很多教程和示例可以开始。

If you are not using Spring in your application there is no need to add extra level of abstraction and dependencies.

如果您的应用程序中没有使用 Spring,则无需添加额外的抽象级别和依赖项。

回答by aviad

You can use Quartz combined with Sprig batch.

您可以将 Quartz 与Sprig batch结合使用。

The former provides API for managing various flows (as complex as you need), persistent storage of job state and api for monitoring and re-running jobs according to their execution status. Another handy library is Spring Batch admin. It has web console and 5 minutes guide.

前者提供用于管理各种流的 API(根据您的需要进行复杂处理)、作业状态的持久存储和用于根据作业的执行状态监控和重新运行作业的 api。另一个方便的库是Spring Batch admin。它有网络控制台和 5 分钟指南。

Quartz is used as scheduler job state persistence is handled by Spring batch.. It can run as standalone java application and also in web/application container (for me Tomcat was enough).

Quartz 用作调度程序作业状态持久性由 Spring 批处理处理。它可以作为独立的 java 应用程序运行,也可以在 web/应用程序容器中运行(对我来说 Tomcat 就足够了)。

Good luck!

祝你好运!

回答by Arun

We have Job storesapi in Java Quartz. This will persist data in the databases about the information of the Job. So i guess this will help you. You can check this linkto get an idea about code and DB structure.

我们Job stores在 Java Quartz 中有api。这将在数​​据库中保存有关作业信息的数据。所以我想这会帮助你。您可以查看此链接以了解代码和数据库结构。