13
13
14
14
import java .lang .reflect .InvocationTargetException ;
15
15
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 .*;
24
17
import java .util .concurrent .atomic .AtomicInteger ;
25
18
26
19
import ch .qos .logback .core .CoreConstants ;
@@ -60,8 +53,7 @@ public Thread newThread(Runnable r) {
60
53
};
61
54
62
55
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 );
65
57
}
66
58
67
59
/**
@@ -78,9 +70,20 @@ static public ExecutorService newExecutorService() {
78
70
* @return ThreadPoolExecutor
79
71
*/
80
72
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
+
84
87
}
85
88
86
89
/**
0 commit comments