zoukankan      html  css  js  c++  java
  • SpringQuartz 任务调度理所当然的陷阱

    Quartz全称是Quartz Enterprise Job Scheduler

    Spring是万能胶, 在企业级应用里面 Spring+Quartz是一个不错的集成的任务调度组合

    看下面这个SchedulerFactory定义

    三个Trigger定义:

         <bean id="scheduledSimpleTrigger1" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
          <property name="jobDetail"> 
            <ref bean="someServiceMethodInvokingJobDetail1"/>
          </property>
          <property name="startDelay">
            <value>3000</value>
          </property>
          <property name="repeatInterval">
            <value>5000</value>
          </property>
        </bean>

    <bean id="scheduledSimpleTrigger2" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
          <property name="jobDetail"> 
            <ref bean="someServiceMethodInvokingJobDetail2"/>
          </property>
          <property name="startDelay">
            <value>3000</value>
          </property>
          <property name="repeatInterval">
            <value>5000</value>
          </property>
        </bean>

    <bean id="scheduledSimpleTrigger3" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
          <property name="jobDetail"> 
            <ref bean="someServiceMethodInvokingJobDetail3"/>
          </property>
          <property name="startDelay">
            <value>3000</value>
          </property>
          <property name="repeatInterval">
            <value>5000</value>
          </property>
        </bean>

    SchedulerFactory定义:

          <bean id="mySchedulerFactory"
               class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
               <property name="autoStartup" value="true"></property>
               <property name="startupDelay" value="3"></property>
               <property name="waitForJobsToCompleteOnShutdown" value="true" />
               <property name="applicationContextSchedulerContextKey">
                   <value>applicationContext</value>
               </property>
               <property name="quartzProperties">
                   <props>
                       <prop key="org.quartz.scheduler.instanceName">mySchedulerFactory</prop>
                    <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
                    <prop key="org.quartz.scheduler.rmi.export">false</prop>
                    <prop key="org.quartz.scheduler.rmi.proxy">false</prop>
                    <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
                    <prop key="org.quartz.threadPool.threadCount">3</prop>
                    <prop key="org.quartz.threadPool.threadPriority">6</prop>
                    <prop key="org.quartz.threadPool.makeThreadsDaemons">true</prop>
                    <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
                   </props>
               </property>
               <property name="triggers">
                   <list>
                        <ref local="scheduledSimpleTrigger1"/>
                        <ref local="scheduledSimpleTrigger2"/>
                        <ref local="scheduledSimpleTrigger3"/>
                   </list>
               </property>
           </bean>

    注意threadCount有三个,Trigger也有三个

    通常会理所当然以为启动应用后,每个TRIGGER都会有一个线程执行,其实不然

    经实际运行测试,三个TRIGGER有的是一个TIRRGER多个线程在运行,有的却长时间得不到执行。

    而我们通常需要保障每个TRIGGER都要有个线程一直守护执行,因此不得已做了个丑陋的配置:

    每个SchedulerFactory只有一个SimpleTrigger,而且这个SchedulerFactory的threadCount设 置为1

    也许还有其他的可配置参数待挖掘,也或者是和当前的运行环境的版本有关:

    当前的运行环境: SPRING:  1.2.8

                             QUARTZ: 1.5.2

    将持续跟踪测试此问题

    1.  有无可平均分配线程的参数配置

    2. 在更新版本下的是否正常

    另:

      测试到在一个SchedulerFactory多个Trigger多个线程下,频繁手动fire下次执行时间也有问题

    以前Quartz更新几乎停止,最近却有些频繁

    前几天刚下载了 Quartz 1.7.0准备测试,Quartz 1.7.1又发布了,看来又有新的修正

    Quartz 1.7.1 Released - 01/24/2010


    Quartz 1.7.1, a minor bug fix release, is now available .

    Many thanks to those who assisted with detailed reports and quick patches.

    Quartz 1.7.0 Released - 01/11/2010


    Quartz 1.7.0 release is now available, which is minor release that includes the following changes:

    • Internal changes to support the awesome new TerracottaJobStore
    • Addition of new trigger type: DateIntervalTrigger
    • Removal of deprecated methods from the API
    • A few small bug fixes
    • Switch to Maven build process
  • 相关阅读:
    c++ this *this
    名称空间
    c++ 静态持续变量
    c++ 数组
    c++ 头文件
    实例化和具体化详解
    在linux下安装eclipse以及运行c++程序的安装步骤
    在centos (linux) 搭建 eclipse c++开发分环境
    Linux上使用Qt Creator进行C/C++开发
    使用Qt Creator 2.60编写C/C++程序
  • 原文地址:https://www.cnblogs.com/kdyi/p/1656567.html
Copyright © 2011-2022 走看看