1、org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
任务代理,代表工作对象,每一个要进行时钟处理的工作任务都要被他所依赖,如:
<bean id="dcImporterJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!--设置依赖于dcImporterOperator实例,作为工作对象 --> <property name="targetObject"> <ref bean="dcImporterOperator" /> </property> <!--设置对dcImporterOperator实例要执行函数是哪一个--> <property name="targetMethod"> <value>import_job</value> </property> <!--设置为线程顺序执行,若为true则是并发处理,默认为true--> <property name="concurrent" value="false" /> </bean>
2、关于引用dcImporterOperator的说明
此类为一个实现了Runnable接口的线程
<bean id="dcImporterOperator" class="com.gemantic.analyse.db.event.dc.importer.impl.DCImporterOperator"> <!--其中定义了一个名为importers的List实例--> <property name="importers"> <list> <!--bean都继承与抽象类Importer,该类实现与接口Callable,应用模板模式实现统一处理功能--> <ref bean="bulEveWinProIncImporter" /> <ref bean="beaEveWinProIncImporter" /> <ref bean="stkBulEveInfoImporter" /> <ref bean="stkBeaEveInfoImporter" /> <ref bean="manHoldChanDetaImporter" /> </list> </property> </bean>
3、org.springframework.scheduling.quartz.SimpleTriggerBean
定时器,负责配置启动时间和执行周期。
<bean id="dcImporterJobTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> <!-- 1 中代理对象作为此类属性--> <property name="jobDetail" ref="dcImporterJobDetail" /> <!--设置服务器启动10000毫秒,单位毫秒 ,默认为0--> <property name="startDelay" value="10000" /> <!-- API上注明:The number of times for the <code>Trigger</code> to repeat firing。trigger重复执行的次数--> <property name="repeatCount" value="0"></property> </bean>
上面配置的是,定时器在服务启动后10秒后启动,并且不重复执行。执行的任务是dcImporterJobDetail
4、org.springframework.scheduling.quartz.SchedulerFactoryBean
Quartz的SchedulerFactory是标准的工厂类,不太适合在Spring环境下使用。此外,为了保证Scheduler能够感知Spring容器的生命周期,完成自动启动和关闭的操作,必须让Scheduler和Spring容器的生命周期相关联。以便在Spring容器启动后,Scheduler自动开始工作,而在Spring容器关闭前,自动关闭Scheduler。为此,Spring提供SchedulerFactoryBean,这个FactoryBean大致拥有以下的功能:
1)以更具Bean风格的方式为Scheduler提供配置信息;
2)让Scheduler和Spring容器的生命周期建立关联,相生相息;
3)通过属性配置部分或全部代替Quartz自身的配置文件。
<bean id="start" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="dcImporterJobTrigger" /> <ref bean="stkEveInfoManagerJobTrigger" /> </list> </property> </bean>