美文网首页
SpringBoot 异步任务、定时任务、邮件任务

SpringBoot 异步任务、定时任务、邮件任务

作者: 奇梦人 | 来源:发表于2019-08-06 22:36 被阅读0次

    1. 异步任务

     // SpringBoot 入口加
    @EnableAsync // 开启异步注解
    
    @RestController
    public class AsyncController{
        @Autowired
        AsyncService asyncService;
     
        @GetMapping("hello")
        public String hello(){
           asyncService.hello();
           return "success";
        }
    }
    
    @service
    public class AsyncService{
    
         @Async  // 告诉 spring 这是一个异步方法
         public void hello(){
          try{
              Thread.sleep();
          }catch(Exception ex){
            
          }
        }
    }
    
    

    相关文章

      网友评论

          本文标题:SpringBoot 异步任务、定时任务、邮件任务

          本文链接:https://www.haomeiwen.com/subject/ismgdctx.html