zoukankan      html  css  js  c++  java
  • SpringBoot普通消息队列线程池配置

     1 package com.liuhuan.study.config;
     2 
     3 import com.google.common.util.concurrent.ThreadFactoryBuilder;
     4 import org.springframework.context.annotation.Bean;
     5 import org.springframework.context.annotation.Configuration;
     6 
     7 import java.util.concurrent.*;
     8 
     9 /**
    10  * @author LiuHuan
    11  * @date 2019-10-08 15:42
    12  * @desc 线程池
    13  */
    14 @Configuration
    15 public class ThreadPoolConfig {
    16 
    17     /**
    18      * 线程池维护线程的最少数量
    19      */
    20     private static final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();
    21 
    22     /**
    23      * 线程池维护线程的最大数量
    24      */
    25     private static final int MAX_POOL_SIZE = 20;
    26 
    27     /**
    28      * 空闲线程等待工作的超时时间
    29      */
    30     private static final long KEEP_ALIVE_TIME = 1000L;
    31 
    32     /**
    33      * 线程池所使用的缓冲队列大小
    34      */
    35     private final static int WORK_QUEUE_SIZE = 10;
    36 
    37 
    38 
    39     /**
    40      * 消息队列线程池
    41      */
    42     @Bean(value = "processThreadPool")
    43     public ExecutorService processThreadPool(){
    44         ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
    45             .setNameFormat("process-thread-%d").build();
    46 
    47         ExecutorService pool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS,
    48             new ArrayBlockingQueue<Runnable>(WORK_QUEUE_SIZE), namedThreadFactory, new ThreadPoolExecutor.DiscardOldestPolicy());
    49         return pool ;
    50     }
    51 
    52 }
  • 相关阅读:
    WslRegisterDistribution failed with error: 0x80370102
    vscode C/C++ 语法检查
    ADO.NET 一(概述)
    线程三(Mutex)
    线程二(Monitor)
    线程一(lock)
    interface Part4(接口中的多态)
    interface Part3(实现:显示和隐式)
    interface Part2(定义接口)
    interface Part1(接口详解)
  • 原文地址:https://www.cnblogs.com/ding-dang/p/13066302.html
Copyright © 2011-2022 走看看