springboot 异步调用 21

2020-04-08  本文已影响0人  张力的程序园

本节讲述springboot的异步调用。

1、环境约束

2、前提约束

@EnableAsync
@Service
public class UserService {
    @Async
    public void query1() throws InterruptedException {
        System.out.println("query1");
        Thread.sleep(5000);
    }

    @Async
    public void query2() throws InterruptedException {
        System.out.println("query2");
        Thread.sleep(5000);
    }

    @Async
    public void query3() throws InterruptedException {
        System.out.println("query3");
        Thread.sleep(5000);
    }
}
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

@SpringBootTest
class SpringbootInitApplicationTests {


    @Resource
    UserService userService;

    @Test
    void contextLoads() throws Exception{
        userService.query1();
        userService.query2();
        userService.query3();
        System.out.println("ok");
    }

}
上一篇下一篇

猜你喜欢

热点阅读