SpringBoot 异步发送内容

启动类上加注解

@EnableAsync

控制层

@RestController
@RequestMapping("asyn")
public class AsyncController {
    @Autowired
    AsynComponent asynComponent;
    @GetMapping("test")
    public String test(){
        asynComponent.run("ssss");
        return "ok";
    }
}

Component

@Component
public class AsynComponent {
    @Async
    public void run(String str){
        for (int i = 0; i < 1000000; i++) {
            System.out.println(str+i);
        }
    }
}

 

posted @ 2021-01-19 10:04  陈彦斌  阅读(94)  评论(0)    收藏  举报