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

位置:首页>文章>详情   分类: 教程分享 > Java教程   阅读(1192)   2023-03-28 11:29:14
线程池创建
    /**
     * 队列用线程
     * @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 mybatis 整合使用讲解介绍,spring boot与mybaties的使用讲解介绍。spring boot mybatis xml mapper方式的入门和通过一个...
Spring Boot validation整合hibernate validator实现数据验证,Spring Boot validation使用说明,Spring Boot validat...