spirng 定时任务

spirng配置如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<!-- 要调用的工作类 ,已经使用注解管理bean-->
<bean id="logJob" class="com.liuli.job.LogJob" />
<!-- 线程执行器配置,用于任务注册 -->
<bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5"/> <!-- 线程池维护线程的最少数量 -->
<property name="maxPoolSize" value="10"/><!-- 线程池维护线程的最大数量 -->
<property name="queueCapacity" value="50"/><!-- 线程池所使用的缓冲队列 -->
    </bean>
    <bean id="jobtask_LogJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="group" value="job_work"/>
<property name="name" value="job_work_name"/>
<property name="concurrent" value="false"/> <!-- 默认为并发执行,FALSE可以控制并发执行 -->
<property name="targetObject" ref="logJob" /> <!-- 任务类 -->
<property name="targetMethod" value="createTable" /> <!-- 任务方法 -->
    </bean>
    <!-- 定义触发时间 -->
    <bean id="cronTrigger_LogJob" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobtask_LogJob" />
        <!-- cron表达式 --><!-- 每月的15号0时0分0秒   秒  分 时 天 月 星期 年-->
        <property name="cronExpression" value="0 42 11 5 * ? *" />
</bean>
     <!--设置调度 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers"> <!-- 可以通过该属性注册多个Trigger -->
<list>
<ref bean="cronTrigger_LogJob" />
</list>
</property>
<property name="taskExecutor" ref="executor" />
</bean>
</beans>
-------Job类如下
public class LogJob {
public void createTable(){
System.out.println("222"+new java.util.Date());
}
}

猜你喜欢

转载自liuli-1234567890.iteye.com/blog/2288566
今日推荐