浏览代码

1. 优化线程池参数,将队列大小设置为可调整

liukx 4 年之前
父节点
当前提交
35f177875a
共有 1 个文件被更改,包括 2 次插入2 次删除
  1. 2 2
      elab-spring/src/main/java/com/elab/spring/utils/ThreadProcessUtils.java

+ 2 - 2
elab-spring/src/main/java/com/elab/spring/utils/ThreadProcessUtils.java

@@ -172,11 +172,11 @@ public class ThreadProcessUtils implements ApplicationContextAware, Initializing
         this.threadProperties = this.applicationContext.getBean(ThreadProperties.class);
         if (this.threadProperties != null && this.threadProperties.getThreadPool() != null) {
             ThreadPoolProperties threadPool = this.threadProperties.getThreadPool();
-            ExecutorService executorService = new ThreadPoolExecutor(threadPool.getCorePoolSize(), threadPool.getMaximumPoolSize(), threadPool.getKeepAliveTime(), TimeUnit.SECONDS, new ArrayBlockingQueue(100));
+            ExecutorService executorService = new ThreadPoolExecutor(threadPool.getCorePoolSize(), threadPool.getMaximumPoolSize(), threadPool.getKeepAliveTime(), TimeUnit.SECONDS, new ArrayBlockingQueue(threadPool.getQueueSize()));
             setExecutorService(executorService);
         } else {
             ThreadPoolProperties threadPool = new ThreadPoolProperties();
-            ExecutorService executorService = new ThreadPoolExecutor(threadPool.getCorePoolSize(), threadPool.getMaximumPoolSize(), threadPool.getKeepAliveTime(), TimeUnit.SECONDS, new ArrayBlockingQueue(100));
+            ExecutorService executorService = new ThreadPoolExecutor(threadPool.getCorePoolSize(), threadPool.getMaximumPoolSize(), threadPool.getKeepAliveTime(), TimeUnit.SECONDS, new ArrayBlockingQueue(threadPool.getQueueSize()));
             setExecutorService(executorService);
         }
     }