Skip to content

Commit 433e168

Browse files
committed
ThreadPoolExecutor now uses LinkedBlockingQueue instead of SynchronousQueue. See comments in the code.
Signed-off-by: Ceki Gulcu <[email protected]>
1 parent 69ce513 commit 433e168

File tree

2 files changed

+16
-122
lines changed

2 files changed

+16
-122
lines changed

Diff for: logback-core/src/main/java/ch/qos/logback/core/util/ExecutorServiceUtil.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@
1313

1414
import java.lang.reflect.InvocationTargetException;
1515
import java.lang.reflect.Method;
16-
import java.util.concurrent.ExecutorService;
17-
import java.util.concurrent.Executors;
18-
import java.util.concurrent.ScheduledExecutorService;
19-
import java.util.concurrent.ScheduledThreadPoolExecutor;
20-
import java.util.concurrent.SynchronousQueue;
21-
import java.util.concurrent.ThreadFactory;
22-
import java.util.concurrent.ThreadPoolExecutor;
23-
import java.util.concurrent.TimeUnit;
16+
import java.util.concurrent.*;
2417
import java.util.concurrent.atomic.AtomicInteger;
2518

2619
import ch.qos.logback.core.CoreConstants;
@@ -60,8 +53,7 @@ public Thread newThread(Runnable r) {
6053
};
6154

6255
static public ScheduledExecutorService newScheduledExecutorService() {
63-
return new ScheduledThreadPoolExecutor(CoreConstants.SCHEDULED_EXECUTOR_POOL_SIZE,
64-
THREAD_FACTORY_FOR_SCHEDULED_EXECUTION_SERVICE);
56+
return new ScheduledThreadPoolExecutor(CoreConstants.SCHEDULED_EXECUTOR_POOL_SIZE, THREAD_FACTORY_FOR_SCHEDULED_EXECUTION_SERVICE);
6557
}
6658

6759
/**
@@ -78,9 +70,20 @@ static public ExecutorService newExecutorService() {
7870
* @return ThreadPoolExecutor
7971
*/
8072
static public ThreadPoolExecutor newThreadPoolExecutor() {
81-
return new ThreadPoolExecutor(CoreConstants.CORE_POOL_SIZE, CoreConstants.MAX_POOL_SIZE, 0L,
82-
TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(),
83-
THREAD_FACTORY_FOR_SCHEDULED_EXECUTION_SERVICE);
73+
74+
// irrelevant parameter when LinkedBlockingQueue is in use
75+
final int maximumPoolSize = CoreConstants.CORE_POOL_SIZE + 1;
76+
final long keepAliveMillis = 100L;
77+
78+
// As of version 1.5.13, the SynchronousQueue was replaced by LinkedBlockingQueue
79+
// This has the effect of queueing jobs immediately and have them run by CORE_POOL_SIZE
80+
// threads. We expect jobs to arrive at a relatively slow pace compared to their duration.
81+
// Note that threads are removed if idle more than keepAliveMillis
82+
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(CoreConstants.CORE_POOL_SIZE, maximumPoolSize, keepAliveMillis, TimeUnit.MILLISECONDS,
83+
new LinkedBlockingQueue<>(), THREAD_FACTORY_FOR_SCHEDULED_EXECUTION_SERVICE);
84+
threadPoolExecutor.allowCoreThreadTimeOut(true);
85+
return threadPoolExecutor;
86+
8487
}
8588

8689
/**

Diff for: logback-core/src/main/java21/ch/qos/logback/core/util/ExecutorServiceUtil.java

-109
This file was deleted.

0 commit comments

Comments
 (0)