1
1
package io .javaoperatorsdk .operator .api .config ;
2
2
3
- import java .util .concurrent .BlockingQueue ;
4
3
import java .util .concurrent .ExecutorService ;
5
4
import java .util .concurrent .LinkedBlockingQueue ;
6
- import java .util .concurrent .RejectedExecutionHandler ;
7
- import java .util .concurrent .ThreadFactory ;
8
5
import java .util .concurrent .ThreadPoolExecutor ;
9
6
import java .util .concurrent .TimeUnit ;
10
7
import java .util .concurrent .atomic .AtomicReference ;
@@ -16,8 +13,7 @@ class ExecutorServiceProducer {
16
13
17
14
static ExecutorService getExecutor (int threadPoolSize ) {
18
15
final var gotSet =
19
- executor .compareAndSet (null , new DebugThreadPoolExecutor (threadPoolSize , threadPoolSize , 0L ,
20
- TimeUnit .MILLISECONDS , new LinkedBlockingQueue <>()));
16
+ executor .compareAndSet (null , new InstrumentedExecutorService (threadPoolSize ));
21
17
final var result = executor .get ();
22
18
if (!gotSet ) {
23
19
// check that we didn't try to change the pool size
@@ -30,35 +26,19 @@ static ExecutorService getExecutor(int threadPoolSize) {
30
26
return result ;
31
27
}
32
28
33
- private static class DebugThreadPoolExecutor extends ThreadPoolExecutor {
29
+ private static class InstrumentedExecutorService extends ThreadPoolExecutor {
30
+ private final boolean debug ;
34
31
35
- public DebugThreadPoolExecutor (int corePoolSize , int maximumPoolSize , long keepAliveTime ,
36
- TimeUnit unit ,
37
- BlockingQueue <Runnable > workQueue ) {
38
- super (corePoolSize , maximumPoolSize , keepAliveTime , unit , workQueue );
39
- }
40
-
41
- public DebugThreadPoolExecutor (int corePoolSize , int maximumPoolSize , long keepAliveTime ,
42
- TimeUnit unit , BlockingQueue <Runnable > workQueue ,
43
- ThreadFactory threadFactory ) {
44
- super (corePoolSize , maximumPoolSize , keepAliveTime , unit , workQueue , threadFactory );
45
- }
46
-
47
- public DebugThreadPoolExecutor (int corePoolSize , int maximumPoolSize , long keepAliveTime ,
48
- TimeUnit unit , BlockingQueue <Runnable > workQueue ,
49
- RejectedExecutionHandler handler ) {
50
- super (corePoolSize , maximumPoolSize , keepAliveTime , unit , workQueue , handler );
51
- }
52
-
53
- public DebugThreadPoolExecutor (int corePoolSize , int maximumPoolSize , long keepAliveTime ,
54
- TimeUnit unit , BlockingQueue <Runnable > workQueue ,
55
- ThreadFactory threadFactory , RejectedExecutionHandler handler ) {
56
- super (corePoolSize , maximumPoolSize , keepAliveTime , unit , workQueue , threadFactory , handler );
32
+ public InstrumentedExecutorService (int corePoolSize ) {
33
+ super (corePoolSize , corePoolSize , 0L , TimeUnit .MILLISECONDS , new LinkedBlockingQueue <>());
34
+ debug = Utils .debugThreadPool ();
57
35
}
58
36
59
37
@ Override
60
38
public void shutdown () {
61
- Thread .dumpStack ();
39
+ if (debug ) {
40
+ Thread .dumpStack ();
41
+ }
62
42
super .shutdown ();
63
43
}
64
44
}
0 commit comments