zoukankan      html  css  js  c++  java
  • 后端——框架——定时任务——quartz——配置

      quartz默认会加载classpath路径下的quartz.properties,若不存在,会加载Jar包中的properties文件。

    它的配置项大致分为五个部分。

    Schedule,ThreadPool, JobStore, Listeners, others

    1、 Schedule

    配置日程,通常只需要设置它的名称即可。

    instanceName:schedule的名称,对应它的name属性。示例org.quartz.scheduler.instanceName: TestScheduler

    instanceId:schedule的ID, 对应它的ID属性,通常分布式环境下才会用到。

    # 当不设置时,默认值为NON-CLUSTER, 设置为ID时,根据ID生成器类生成,
    # 设置为SYS_PROP时,获取org.quartz.scheduler.instanceId系统属性
    org.quartz.scheduler.instanceId: AUTO
    

      instanceIdGenerator.classID生成器,

    org.quartz.scheduler.instanceIdGenerator.class:org.quartz.simpl.HostnameInstanceIdGenerator
    

      jobFactory.class:创建Job实例的工厂类

    key.SOME_KEY: 添加键值对

    # 添加键值对test_key:test_value
    org.quartz.context.key.test_key:test_value
    

    2、ThreadPool

    threadName:线程的名称,通常调试的时候会用到

    threadNamePrefix线程名称前缀

    makeSchedulerThreadDaemon:是否将线程(运行Scheduler)设置为后台守护进程。默认为false

    makeThreadsDaemons是否将线程设置为后台守护进程,默认为false

    threadsInheritGroupOfInitializingThread

    threadsInheritContextClassLoaderOfInitializingThread

    3、JobStore

    3.1   RAMJobStore

      Class:JobStore的类型,固定值org.quartz.simpl.RAMJobStore

    # RAMJobStore type
    org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
    

      misfireThreshold: 未正常触发的时间阈值,超出该时间,视为错误,抛出异常。它的单位为毫秒

    # the number of milliseconds the scheduler will "tolerate" a trigger
    # to pass its next-fire-time by, before being considered "misfired".
    # default value is 60000, one minute
    org.quartz.jobStore.misfireThreshold: 60000
    

    3.2   JDBCJobStore

    3.2.1   common

    配置项前缀为org.quartz.jobStore

    driverDelegateClass:用于操作数据库的类。

    # create insert update delete quartz related tables
    org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
    

      driverDelegateInitString:在初始化driverDelegateClass时,为其设置初始化参数。格式为“key=value|key1=value1”,分隔符是“|”。

    dataSource:数据源的名称

    tablePrefix:quartz数据库的表名前缀,使用默认值”QRTZ_”即可。

    useProperties: 在存储属性时,当值为true时,表示所有的属性为字符串,当为false时,会对属性进行序列化操作,并存储为BLOB类型。

    # The use properties flag instructs JDBCJobStore that all values in JobDataMaps will be Strings, 
    # and therefore can be stored as name-value pairs, 
    # rather than storing more complex objects in their serialized form in the BLOB column
    org.quartz.jobStore.useProperties:  true
    

      misfireThreshold与RAMJobStore的同名配置项含义相同

    isClustered是否拥有多个scheduler实例,是否处于分布式环境

    clusterCheckinInterval分布式环境下检测其他scheduler实例的时间间隔。

    dontSetAutoCommitFalse: 设置Connection对象的autoCommit属性为false。

    selectWithLockSQL:查询语句,添加行锁。

    acquireTriggersWithinLock: 获取Trigger,添加锁

    3.2.2   数据源

    配置项的前缀为org.quartz.datasource.NAME其中NAME为数据源的名称,任意的字符串

    Driver:驱动类

    url:数据库地址

    user:用户名

    password:密码

    maxConnections:最大连接数

    validationQuery:测试连接是否成功使用的SQL脚本

    idleConnectionValidationSeconds:测试连接的时间间隔,在此间隔内不执行连接测试,对应C3P0的idleConnectionTestPeriod

    validateOnCheckout:从连接池获取对象时进行连接测试。对应C3P0的testConnectionOnCheckOut。

    discardIdleConnectionsSeconds:连接对象保持空闲状态的最大时间,当超出此时间,Connection对象被释放,连接池中的连接对象变少。对应C3P0的maxIdleTime。当设置为0时,禁用此功能。会导致线程池不会缩小(shrink)。

    idleWaitTime:指定空闲时间,超出空闲时间之后,去查询数据库。值不宜过小,过小会导致查询次数激增。低于1秒时无效。

    dbFailureRetryInterval:查询数据库失败之后,重试的时间间隔。

    # 设置为3秒
    org.quartz.scheduler.dbFailureRetryInterval:3000
    

      3.2.3   事务

    userTransactionURL: 无需配置,通常由spring管理事务。

    wrapJobExecutionInUserTransaction: 无需配置。

    txIsolationLevelSerializable是否设置事务的隔离级别为Serializable

    4、 Listener

    TriggerListener:

    # configure TriggerListener
    org.quartz.triggerListener.my_trigger_listener.class = learn.quartz.MyTriggerListener
    

      JobListener:

    # configure JobListener 
    org.quartz.jobListener.my_job_listener.class = learn.quartz.MyJobListener
    
  • 相关阅读:
    [转]编译原理书籍推荐
    [转]让 Dreamweaver 支持 Emmet(原ZenCoding)
    [转]Zend Studio GitHub 使用教程
    [转]如何用EGit插件把github上的项目clone到eclipse
    [转]github更新自己fork的代码
    [转]少走弯路:学习编译原理的相关建议
    [转]关于计算机研究生报考方向的简要介绍
    [转]zend studio 安装git插件
    [转]如何在SAE上安装原版wordpress
    C语言博客作业02循环结构
  • 原文地址:https://www.cnblogs.com/rain144576/p/14749918.html
Copyright © 2011-2022 走看看