Blame view

fw-valhalla-common/src/main/java/cn/fw/valhalla/common/utils/ThreadPoolUtil.java 1.06 KB
03d7ac84   张志伟   feature(*): 添加续保、...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  package cn.fw.valhalla.common.utils;
  
  import cn.hutool.core.thread.ExecutorBuilder;
  
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.LinkedBlockingQueue;
  
  /**
   * ThreadPoolUtl
   *
   * @author : kurisu
   * @version : 2.0
   * @className : ThreadPoolUtl
   * @description : ThreadPoolUtl
   * @date : 2023-04-19 17:31
   */
  public class ThreadPoolUtil {
      private static volatile ThreadPoolUtil INSTANCE;
      private final ExecutorService executor;
  
      private ThreadPoolUtil() {
          this.executor = ExecutorBuilder.create()
                  .setCorePoolSize(20)
                  .setMaxPoolSize(60)
                  .setWorkQueue(new LinkedBlockingQueue<>(4096))
                  .build();
      }
  
      public static ThreadPoolUtil getInstance() {
          if (INSTANCE == null) {
              synchronized (ThreadPoolUtil.class) {
                  if (INSTANCE == null) {
                      INSTANCE = new ThreadPoolUtil();
                  }
              }
          }
          return INSTANCE;
      }
  
      public ExecutorService getExecutor() {
          return executor;
      }
  }