Переглянути джерело

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

liukx 4 роки тому
батько
коміт
35f177875a

+ 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);
         }
     }