码迷,mamicode.com
首页 > 编程语言 > 详细

spring task

时间:2017-05-12 13:26:08      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:ini   scan   jndi数据源   type   component   art   resource   pru   文件   

quartz采用多线程,定时任务之间不受影响。spring task采用单线程,定时任务之间会相互阻塞,完成一个任务才会执行下一个。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">

    <mvc:annotation-driven />     
    <tx:annotation-driven transaction-manager="transactionManager" /> 
    <task:annotation-driven/>  
    
    <bean id="inbound_call_finish_task" class="com.yd.iwmsc.caller.logic.IWMSC_busi_inboundCaller" />
    <bean id="outbound_call_finish_task" class="com.yd.iwmsc.caller.logic.IWMSC_busi_outboundCaller" />
    <task:scheduled-tasks>  
        <task:scheduled ref="inbound_call_finish_task" method="call_finish" cron="0 0/3 * * * ?" />  
        <task:scheduled ref="outbound_call_finish_task" method="call_finish" cron="0 0/3 * * * ?"/>  
    </task:scheduled-tasks>
    
    <!--  加载配置文件-->
   <!--  <context:property-placeholder location="classpath:config.properties"/> -->
    
    <!--  JNDI数据源-->    
     <jee:jndi-lookup id="dataSource" jndi-name="jndi_wmsce" resource-ref="true"/>

    <!-- SPRING JDBC -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="dataSource"/> 
    </bean>
    
    <!-- SPRING 事务管理-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>    
    
    <!--  应用上线文初始化Bean-->
    <!-- <bean class="com.yd.common.runtime.CIPRuntimeContextInitializer" />  -->
    
    <!-- dao,service,controller,component scan -->
    <context:component-scan base-package="com.yd.iwmsc"  />
    <context:component-scan base-package="com.yd.wmsc"  />
    <context:component-scan base-package="com.yd.common.function" />
    <context:component-scan base-package="com.yd.common.auth" />
</beans>

或者用@Scheduled注解

package com.yd.wmsc.util;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class TestAop2 {
    
    @Scheduled(cron="0 0/1 * * * ?")
    public void test() {
        System.out.println("定时器2开始");
    }

}

 

spring task

标签:ini   scan   jndi数据源   type   component   art   resource   pru   文件   

原文地址:http://www.cnblogs.com/tonggc1668/p/6844933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!