zoukankan      html  css  js  c++  java
  • SpringMVC 异步与定时使用示例

    1.Spring 的xml配置:

    <aop:aspectj-autoproxy/>
    <task:annotation-driven executor="annotationExecutor" scheduler="scheduler"/>
    <!-- 支持 @Async 注解 -->
    <task:executor id="annotationExecutor" pool-size="20"/>
    <!--配置线程池-->
    <task:scheduler id="scheduler" pool-size="10" />

    2.定义异步同步方法:

    package com.leibao.http.async;
    /**
     * User: 
     * Date: 13:48 2017/12/13
     * Email: 
     */
    @Service
    public class IdCardAuthAsync {
        @Autowired
        private ReportModelAuthInfoService reportModelAuthInfoService;
        @Autowired
        private ReportService reportService;
        private final static Logger logger = LoggerFactory.getLogger(IdCardAuthAsync.class);
        @Async
        public void getIdcardAuthDeal(Map map,User user,Report report) {
            logger.info("身份证认证开始");
        }
       @Scheduled(cron = "0/10 * * * * ? ")
        public void checkEmailByUndetected() {
            System.out.println("定时检测!!");
        }
    }

    3.异步的使用:

    [1]封装实例:

    @Autowired
    private IdCardAuthAsync idCardAuthAsync;

    [2].调用:

    idCardAuthAsync.getIdcardAuthDeal(map,updateUser,report);
  • 相关阅读:
    hdu 1381 Crazy Search
    hdu 5131 Song Jiang's rank list
    poj 2251 Dungeon Master
    hdu 4941 Magical Forest
    hdu 1728 逃离迷宫
    hdu 2612 Find a way
    hdu 3288 Resource Allocation
    hdu 1272 小希的迷宫
    hdu 5224 Tom and paper
    hdu 5104 Primes Problem
  • 原文地址:https://www.cnblogs.com/yysbolg/p/10652920.html
Copyright © 2011-2022 走看看