• Quartz配置


    1. Quartz主要配置

    属性名称是否必选类型默认值说明
    org.quartz.scheduler.instanceName String QuartzScheduler Schedule调度器的实体名字
    org.quartz.scheduler.instanceId String NON_CLUSTERED Schedule调度器的实体的Id,必须唯一。
    1. 当你想生成intanceId的时候可以设置为AUTO
    2. 当你想从系统属性org.quartz.scheduler.instanceId取值时可以设置为SYS_PROP
    org.quartz.scheduler.instanceIdGenerator.class String(类名) org.quartz.simpl.SimpleInstanceIdGenerator 生成Schudule实体Id的类,只有在属性org.quartz.scheduler.instanceId设置为AUTO时使用,默认的实现org.quartz.scheduler.SimpleInstanceGenerator是基于主机名称和时间戳生成。其他的实现查看具体的文档
    org.quartz.scheduler.threadName String instanceName + ‘_QuartzSchedulerThread’ Scheduler线程的名称
    org.quartz.scheduler.makeSchedulerThreadDaemon boolean false 指定Scheduler是否以守护线程(服务)运行
    org.quartz.scheduler.threadsInheritContextClassLoaderOfInitializer boolean false 目前不太理解
    org.quartz.scheduler.idleWaitTime long 30000 当调度程序空闲时,在重新查询可用触发器之前,调度程序将等待毫秒的时间数。不建议少于5000ms,而少于1000是不合法的参数
    org.quartz.scheduler.doFailureRetryInterval long 15000 使用JobStore(比如连接数据库)时Schueduler检测到失去数据库连接后重新尝试连接的毫秒数
    org.quartz.scheduler.classLoadHelper.class String(类名) org.quartz.simpl.CascadingClassLoaderHelper 目前不太了解
    org.quartz.scheduler.jobFactory.class String(类名) org.quartz.simpl.PropertySettingJobFctory 给Scheduler Context、Job、Trigger的JobDataMaps设置属性值的方式
    org.quartz.contenxt.key.SOME_KEY String None 键值对,保存在Scheduler Context中,比如有这样的配置org.quartz.shceduler.key.MyKey=MyValue,则在Scheduler Context中赋值方式为scheduler.getContext().put(“MyKey”, “MyValue”
    org.quartz.scheduler.userTransactionURL String(url) java:comp/UserTransaction 事务管理JNDI URL地址。只有当Quartz使用JobStoreCMT和org.quartz.scheduler.wrapJobExecutionInUserTransaction 设置为true时使用
    org.quartz.scheduler.wrapJobExecutionInUserTransaction boolean false 只有当你在执行一个Job时想使用UserTransaction时设置为true,参考@ExecuteInJTATransaction 注解
    org.quartz.scheduler.skipUpdateCheck boolean false 是否跳过版本检测。可以设置系统参数org.terracotta.quartz.skipUpdateCheck=true或者在JAVA命令行使用-D选项。在正式库运行时应设置为true。
    org.quartz.scheduler.batchTriggerAcquisitionMaxCount int 1 在同一时间运行Scheduler获取trigger的数量。如果设置的数量>1,并且使用JDBC JobStore,则属性org.quartz.jobStore.acquireTriggersWithinLock应设置为true,可以避破坏数据。
    org.quartz.scheduler.batchTriggerAcquisitionFireAheadTimeWindow long 0 运行Scheduler在获取和触发tigger的提前的时间。

    2. 线程池配置

    2.1 主要配置

    属性名称是否必选类型默认值说明
    org.quartz.threadPool.class String(类名) null Scheduler使用的线程池名称,实现了ThreadPool接口,参考org.quartz.simpl.SimpleThreadPool
    org.quartz.threadPool.threadCount int -1 线程池里面的线程的数据,取值在1-100
    org.quartz.threadPool.threadPriority int Thread.NORM_PRIORITY (5) 线程的优先级,取值在Thread.MIN_PRIORITY(1)到Threa.MAX_PRIORITY(10)

    2.2 线程池的简单配置

    属性名称是否必选类型默认值说明
    org.quartz.threadPool.makeThreadsDaemons boolean fale 指定在线程池里面创建的线程是否是守护线程
    org.quartz.threadPool.threadsInheritGroupOfInitializingThread boolean true  
    org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread boolean false  
    org.quartz.threadPool.threadNamePrefix String [Scheduler Name]_Workder 指定线程池里面线程的名字的前缀

    3. Listener配置

    在实例化StdSchedulerFactory的时候可以注册一个全局的监听器到Scheduler中,全局监听器会监听每一个Job和Trigger的触发事件。 
    全局监听器必选有一个无参的构造函数,并且属性值只能是基本类型(包括String)。

    配置例子:

    //trigger listener配置
    org.quartz.triggerListener.NAME = package.className
    org.quartz.triggerListener.NAME.propName = propValue
    //job listener配置
    org.quartz.jobListener.NAME = package.className
    org.quartz.jobListener.NAME.propName = propValue
    

      

    4. JobStore配置

    JobStore是Scheduler在运行时用来存储相关的信息的,比如Job, Trigger。

    4.1 RAMJobStore

    RAMJobStore实现类是在内存中存储信息的,程序一旦结束便丢失了相关的信息。

    属性名称是否必选类型默认值说明
    org.quartz.jobStore.class String(类名) org.quartz.simpl.RAMJobStore 指定使用的JobStore
    org.quartz.jobStore.misfireThreshold int 60000 触发器失败后下次触发的时间间隔

    4.2 JDBCJobStore和JobStoreTX

    JDBCJobStore和JobStoreTX都使用关系数据库来存储Schedule相关的信息。

    JobStoreTX在每次执行任务后都使用commint或者rollback来提交更改。

    如果在一个标准的独立应用或者在一个没有使用JTA事务管理的应用中使用Quartz,JDBCJobStore是一个不错的选择。

    JobStoreTX的配置如下:

    属性名称是否必选类型默认值说明
    org.quartz.jobStore.class String(类名) org.quartz.simpl.jdbcjobstore.JobStoreTX 使用JobStoreTX
    org.quartz.jobStore.driverDelegateClass String(类名) null 使用的数据库驱动,具体的驱动列表详情如下
    org.quartz.jobStore.dataSource String null 使用的数据源名称,具体参照数据源配置
    org.quartz.jobStore.tablePrefix String QRTZ_ 表的前缀
    org.quartz.jobStore.userProperties boolean false 标示在JobDataMaps的数据全部是String
    org.quartz.jobStore.misfireThreshold int 60000 触发器触发失败后再次触犯的时间间隔
    org.quartz.jobStore.isClustered boolean false 如果有多个调度器实体的话则必须设置为true
    org.quartz.jobStore.clusterCheckinInterval long 15000 检查集群下的其他调度器实体的事件间隔
    org.quartz.jobStore.maxMisfiresToHandleAtATime int 20  
    org.quartz.jobStore.dontSetAutoCommintFalse boolean false  
    org.quartz.jobStore.selectWithLockSQL String select * from {0}locks where sched_name = {1} and lock_name = ? for update  
    org.quartz.jobStore.txlsolationLevelSerializable boolean false  
    org.quartz.jobStore.acquireTriggersWithinLocal boolean false  
    org.quartz.jobStore.lockHandler.class String null  
    org.quartz.jobStore.driverDelegateInitString String null  

    4.2.1 org.quartz.jobStore.driverDelegateClass数据库驱动列表

    • org.quartz.impl.jdbcstore.StdJDBCDelegate 适用于完全兼容JDBC的驱动
    • org.quartz.impl.jdbcstore.MSSQLDelegate 适用于Miscrosoft SQL Server和Sybase数据库
    • org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
    • org.quartz.impl.jdbcjobstore.WebLogicDelegate
    • org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
    • org.quartz.impl.jdbcjobstore.oracle.WebLogicOracleDelegate
    • org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate
    • org.quartz.impl.jdbcjobstore.CloudscapeDelegate
    • org.quartz.impl.jdbcjobstore.DB2v6Delegate
    • org.quartz.impl.jdbcjobstore.DB2v7Delegate
    • org.quartz.impl.jdbcjobstore.DB2v8Delegate
    • org.quartz.impl.jdbcjobstore.HSQLDBDelegate
    • org.quartz.impl.jdbcjobstore.PointbaseDelegate
    • org.quartz.impl.jdbcjobstore.SybaseDelegate

    5. 集群,使用JDBCJobStore和JobStoreTX

    在JobStore使用JDBCJobStore、JobStoreTX、JobStoreCMT的情况下可以使用Quartz的集群特性,示意图如下:

    简单的配置如下:

    //主要配置
    org.quartz.scheduler.instanceName = MyClusteredScheduler
    org.quartz.scheduler.instanceId = AUTO
    
    //配置数据池连接
    org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
    org.quartz.threadPool.threadCount = 25
    org.quartz.threadPool.treadPriority = 5
    
    //JobStore配置
    org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
    org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcstore.oracle.OracleDelegate
    org.quartz.jobStore.userProperties = true
    org.quartz.jobStore.dataSource = myDS
    org.quartz.jobStore.misfireThreshold = 60000
    
    org.quartz.jobStore.isClustered = true
    org.quartz.jobStore.clusterCheckinInterval = 20000
    
    //DataSource数据源配置
    org.quartz.dataSource.myDS.driver = oracle.jdbc.driver.OracleDriver
    org.quartz.dataSource.myDS.URL = jdbc:oracle:thin:@localhost:1521:dev
    org.quartz.dataSource.myDS.user = quartz
    org.quartz.dataSource.myDS.password = quartz
    org.quartz.dataSource.myDS.maxConnections = 5
    org.quartz.dataSource.myDS.validationQuery=select 0 from dual
    

      

  • 相关阅读:
    数据结构之线性表
    在Swift中,如何像Objective-C定义可选接口?
    ios开发--常用宏定义(部分转)
    ios开发--KVO浅析
    2015年 移动开发都有哪些热点?
    HTML5七大优势“逼宫”APP
    ios 中使用SBJson拼接和解析json
    iOS-动态调整UITableViewCell的高度
    iOS App Launch Option
    Swift自适应布局(Adaptive Layout)教程
  • 原文地址:https://www.cnblogs.com/yuyu666/p/10062501.html
Copyright © 2020-2023  润新知