quartz spring 简单用法

	
    <bean id="emailCustomizeJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject">
            <ref bean="emailCustomizeServiceImpl" />
        </property>
        <!-- 调用类中的方法 -->
        <property name="targetMethod">
            <value>emailCustomizeJob</value>
        </property>
    </bean>

    <!-- 定义触发时间 -->
    <bean id="emailCustomizeJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref bean="emailCustomizeJob" />
        </property>
        <!-- cron表达式 -->
        <property name="cronExpression">
        	<!-- 每三分钟,触发一次。 -->
            <value>0/3 * * * * ?</value>
        </property>
    </bean>
    <!-- 启动定时任务  -->
	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="applicationContextSchedulerContextKey" value="applicationContextKey" />
		<property name="configLocation" value="classpath:quartz.properties" />
		<property name="globalTriggerListeners">
			<list>
				<ref bean="globleLogListener" />
			</list>
		</property>
		<property name="triggers">
			<list>
				<!-- 邮件定制通知作业 -->
				<ref bean="emailCustomizeJobTrigger"/>
			</list>
		</property>
	</bean>

SchedulerFactoryBean 为返回的为Scheduler

以上quartz保存在数据库中。

org.quartz.scheduler.instanceName = quartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.implbcjobstore.StdJDBCDelegate
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.OracleDelegate

#org.quartz.jobStore.useProperties = true
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered = false  
org.quartz.jobStore.maxMisfiresToHandleAtATime=1

以上是quartz结合spring的简单应用。

猜你喜欢

转载自qq85609655.iteye.com/blog/1132820