英文:
using mulit thread with spring boot
问题
我正在使用Spring Boot开发一个项目。
如果我创建一个类像这样,线程不起作用。
DAO按顺序工作。
示例(1.2.3.4.5.....100)
服务类
    for(int i = 1; i <= 30; j++) {
      threadServiceMethod(i);
    }
ThreadService类
    @Async
    public CompletableFuture<List<DTO>> threadServiceMethod(int i) {
            return CompletableFuture.completedFuture(DAO方法);
    }
DAO类
    public List<Dto> daoMethod() {
        //选择代码
    }
但是,如果将@Async连接到daoMethod,它会起作用。
但是,客户端接收到的结果值是null。
ThreadService类
    public CompletableFuture<List<DTO>> threadServiceMethod(int i) {
            return CompletableFuture.completedFuture(DAO方法);
    }
DAO类
    @Async
    public List<Dto> daoMethod() {
        //选择代码
    }
如果对threadmethod和dao使用@Async,日志将按顺序输出。
为什么会这样工作呢?
帮帮我 
英文:
I am working on a project using Spring Boot.
If I create a class like this the thread doesn't work.
DAO works sequentially.
example (1.2.3.4.5.....100)
Service class
    for(int i = 1; i <= 30; j++) {
      threadServiceMethod(i);
    }
ThreadService class
    @Async
    public CompletableFuture<List<DTO>> threadServiceMethod(int i) {
            return CompletableFuture.completedFuture(DAO method);
    }
DAO class
    public List<Dto> daoMethod() {
        //select code
    }
But It works if @Async is connected to daoMethod
However, the result value that the client receives is null.
ThreadService class
    public CompletableFuture<List<DTO>> threadServiceMethod(int i) {
            return CompletableFuture.completedFuture(DAO method);
    }
DAO class
    @Async
    public List<Dto> daoMethod() {
        //select code
    }
If @async is used for threadmethod and dao, logs are output sequentially.
Why does it work like this??
help me 
专注分享java语言的经验与见解,让所有开发者获益!



评论