其他分享
首页 > 其他分享> > springboot使用多线程

springboot使用多线程

作者:互联网

一、使用ExecutorService

1、配置线程池数量

@Configuration
public class ThreadPoolConfig {

    @Bean
    public ExecutorService getThreadPool(){
        return Executors.newFixedThreadPool(8);
    }

}

2、service 使用方式。

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private ExecutorService executorService;

    @Override
    public User query() {
        executorService.execute(new Runnable() {
            public void run() {
                System.out.println("Asynchronous task");
            }
        });
        User user = new User();
        return user;
    }

}

标签:ExecutorService,return,springboot,User,使用,new,多线程,public,user
来源: https://blog.csdn.net/xiaoyaozizai1/article/details/122644971