springboot异步调用demo

阅读更多
第一步建立一个类
package com.zys.async;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

@Component
@EnableAsync //开启异步调用
public class AsyncDemo {


@Async
    public void sendSms(){
        System.out.println("####sendSms####   2");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        System.out.println("####sendSms####   3");
    }
}


第二步:测试即可
@Autowired

private AsyncDemo asyncDemo;



在controller 测试即可
asyncDemo.sendSms();

你可能感兴趣的:(Async,springboot)