• spring task


    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开始");
        }
    
    }
  • 相关阅读:
    DNX SDK版本 “dnx-clr-win-x86.1.0.0-beta5”无法安装
    【循序渐进MVC】第一回——一物多用Project.json依赖关系之dependencies节点
    ASP.NET页面中去除VIEWSTATE视图状态乱码
    git入门操作命令(转载)
    论火车票订单系统中并发问题和锁机制的探讨(转载)
    如何取消MSSQL自带智能提示步骤,使用第三方智能提示插件
    查看Windows服务器登录日志
    浅谈分布式计算系统和集群系统的区别
    数据库设计优化经验谈(转载)
    程序性能优化之防止装箱将拆装箱最小化
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/6844933.html
Copyright © 2020-2023  润新知