zoukankan      html  css  js  c++  java
  • 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开始");
        }
    
    }
  • 相关阅读:
    python中创建实例属性
    Python中if __name__ == "__main__": 的理解
    模块
    python函数式编程
    python-复杂生成式
    生成器的测试
    mysql乱码配置
    javascript
    Sql Server 2008 R2 下载地址
    Microsoft Data Access Components 2.8
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/6844933.html
Copyright © 2011-2022 走看看