quartz有哪些特性

来源:互联网 发布:中国制造 知乎 编辑:程序博客网 时间:2024/05/01 06:17

版本:2.2.1

通过程序示例学习开源软件,是一种很好的方式,下面这些示例基本包括了quartz的所有的特性。

1、Example5 - Handling Job Misfires

当没有按时执行任务时,可以通过设置,让该任务立即执行。

http://quartz-scheduler.org/documentation/quartz-2.2.x/examples/Example5

 

Note: The trigger for job #2 is set with a misfireinstruction that will cause it to reschedule with the existing repeat count.This policy forces quartz to refire the trigger as soon as possible. Job #1uses the default "smart" misfire policy for simple triggers, whichcauses the trigger to fire at it's next normal execution time.

 

2、Example6 - Dealing with Job Exceptions

当任务出现异常时,可以捕获异常,然后通过对JobExecutionException进行设置达到立即执行该任务还是取消该任务的目的。

http://quartz-scheduler.org/documentation/quartz-2.2.x/examples/Example6

 

3、Exampl7 - Interrupting Jobs

可以中断正在执行的任务。

sched.interrupt(job.getKey());

 

4、Example 9 - Job Listeners

Use job listeners to have one job trigger another job,building a simple workflow。

 

5、Example 10 - Using Quartz Plug-Ins

通过xml文件来加载任务。

 

6、Example 12 - Remote Job Scheduling using RMI

客户端通过RMI让服务端的scheduler执行任务。

 

7、Example 13 - Clustered Quartz

在本地运行了下这个例子,确实可以实现负载均衡和容错,应该还有坑,需要再研究。

优点:

(1)负载均衡。就是不同的node可能会执行的不同的定时任务,可能node1执行一个任务,此时node2会执行另一个任务,这样做会比较好的做到负载均衡。

(2)容错。一个node挂了,不会 影响到其他node上的定时任务。每个node上的quartz定期的向数据库里登记它们的时间,如果某个实例在一定的时间内没有登记,就表示这个实例挂了 ,其它的实例就会重新获取这个挂了的实例所执行的任务。 

缺点:

(1)quartz需要使用jdbc-jobstore,quartz本身的性能减低。

(2)所有节点所在机器的时间相差必须在一秒之内。 Never runclustering on separate machines, unless their clocks are synchronized usingsome form of time-sync service (daemon) that runs very regularly (the clocksmust be within a second of each other).

(3)如果还有其他没用集群的quartz的话不能用这个jdbc-jobstore,不然可能会出问题。

(4)所有的节点都需要跑quartz实例,那么每个节点上都需要额外的线程池。

(5)配置文件中的数据库密码必须是明文。

如果要支持密文,修改类org.quartz.impl.StdSchedulerFactory的929行。

(6)数据库的schema必须是public。

如果要支持指定schema,修改配置文件的org.quartz.jobStore.tablePrefix这一项。

 

8、Example15 - TC Clustered Quartz

使用Terracotta,而不是使用数据库,来部署clusterquartz。

 

9、CronTrigger Misfire Instructions和SimpleTriggerMisfire Instructions

 

 

 

参考链接:

http://quartz-scheduler.org/documentation/quartz-2.2.x/examples/

http://ahuaxuan.iteye.com/blog/114965

http://www.mkyong.com/java/how-to-list-all-jobs-in-the-quartz-scheduler/


0 0
原创粉丝点击