Skip to content

Instantly share code, notes, and snippets.

@EdwardsBean
Created November 12, 2014 09:29
Show Gist options
  • Save EdwardsBean/41ab2e2b11b19273eb97 to your computer and use it in GitHub Desktop.
Save EdwardsBean/41ab2e2b11b19273eb97 to your computer and use it in GitHub Desktop.
spring quartz配置示例
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--要调用的工作类-->
<bean id="hourJob" class="com.baidu.grab.schedule.PM25HourJob"/>
<!--调用对象和方法-->
<bean id="hourTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="hourJob"/>
<property name="targetMethod" value="grab"/>
</bean>
<!--触发时间-->
<bean id="runTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="hourTask"/>
<!--47分的时候执行一次任务-->
<property name="cronExpression" value="0 47 * * * ?"/>
</bean>
<!--要调用的工作类-->
<bean id="tpHourJob" class="com.baidu.grab.schedule.ThinkPageHourJob"/>
<!--调用对象和方法-->
<bean id="tpHourTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="tpHourJob"/>
<property name="targetMethod" value="grab"/>
</bean>
<!--触发时间-->
<bean id="tpRunTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="tpHourTask"/>
<!--5分的时候执行一次任务-->
<property name="cronExpression" value="0 5 * * * ?"/>
</bean>
<!--设置调度 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="quartzManager" lazy-init="true" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="runTime"/>
<ref bean="tpRunTime"/>
</list>
</property>
<property name="taskExecutor" ref="executor"/>
</bean>
<!-- 线程执行器配置,用于任务注册 -->
<bean id="executor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="10" />
<property name="queueCapacity" value="500" />
</bean>
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment