首页> 文章> 详情

Spring boot 项目优雅关闭while循环线程

教程分享 > Java教程 (2284) 2024-04-17 12:31:28
线程池创建
    /**
     * 队列用线程
     * @return
     */
    @Bean(name = "queuePool")
    public ThreadPoolExecutor queuePool(){
        ThreadPoolExecutor pool = new ThreadPoolExecutor(8, 16,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(200),
                new ThreadPoolExecutor.CallerRunsPolicy());
        return pool;
    }
while 循环线程创建
public AsynCompute{
    
    @Resource(name = "queuePool")
    ThreadPoolExecutor executorService;
    
     @PostConstruct
    public void process(){
    
         executorService.execute(()->{
              while (true&&!executorService.isShutdown()){
                  //TODO 具体业务
              } 
         });
    }
}
注意点:executorService.isShutdown()判断线程池是否关闭状态
https://www.leftso.com/article/779.html

相关文章
线程池创建 /** * 队列用线程 * @return */ @Bean(name = "queuePool") public Thread...
在这篇文章中,我们将讨论有关使用异步任务执行程序功能在不同线程中执行任务的Spring boot异步执行支持。我们将看看在Spring项目中配置SimpleAsyncTaskExecutor,C...
引言    通过之前spring boot mybatis 整合的讲解: spring boot mybaties整合  (spring boot mybaties 整合 基于Java注解方式写...
Spring Boot 2.0,Spring框架的Spring Boot 中的Spring Boot Actuator变化讲解。并且了解如何在Spring Boot 2.0中使用Actuator...
Spring Boot 2.0 绑定properties属性资源文件 Spring Boot 2.0 读取properties配置文件值 Spring Boot 2.0获取properties配...
spring boot入门,spring boot是一个崭新的spring框架分支项目,本文讲解其属性配置相关
spring boot 1.5整合redis实现spring的缓存框架,spring boot,redis
spring boot是一个崭新的spring框架分支项目,本文讲解基本的数据库配置
Spring Boot validation整合hibernate validator实现数据验证,Spring Boot validation使用说明,Spring Boot validat...
spring boot mybatis 整合使用讲解介绍,spring boot与MyBatis的使用讲解介绍。spring boot mybatis xml mapper方式的入门和通过一个简...
spring boot又一个spring框架的经典项目,本文讲解spring boot入门的环境配置以及第一个项目,Spring Boot 入门教程
Spring Boot 2.0 Redis整合,通过spring boot 2.0整合Redis作为spring缓存框架的实现。
spring boot 导入本地jar包spring boot maven 打war包时候导入本地jar包
spring boot框架整合MyBatis数据库暂时选用MySQL
问题描述Mac 编译Spring boot项目的时候报错:java.lang.RuntimeException: Cannot reconnect. at org.jetbrains.idea...