美文网首页
11_springboot异步执行方法极简demo

11_springboot异步执行方法极简demo

作者: cjxz | 来源:发表于2020-05-18 19:59 被阅读0次

springboot异步demo

1.开启异步功能@EnableAsync
2.在需要异步执行的方法上面增加@Async
完毕
真是极简

@SpringBootApplication
@EnableAsync
public class StartMain {
    public static void main(String[] args) {
        SpringApplication.run(StartMain.class,args);
    }
}
    @Async
    public void async1() throws InterruptedException {
        for(int i =0 ; i < 10 ; i ++){
            Thread.sleep(100);
            System.out.println("com.cjxz.service.impl.AsyncServiceImpl.async1:"+i);
        }
    }

相关文章

网友评论

      本文标题:11_springboot异步执行方法极简demo

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