4
4
import org .jetbrains .annotations .NotNull ;
5
5
import org .jetbrains .annotations .TestOnly ;
6
6
7
- import java .util .concurrent .ExecutorService ;
8
- import java .util .concurrent .SynchronousQueue ;
9
- import java .util .concurrent .ThreadPoolExecutor ;
10
- import java .util .concurrent .TimeUnit ;
7
+ import java .util .concurrent .*;
11
8
12
9
/**
13
10
* A thread pool for long-running workers needed for handling child processes or network requests,
@@ -19,19 +16,26 @@ public class ProcessIOExecutorService extends ThreadPoolExecutor {
19
16
public static final ExecutorService INSTANCE = new ProcessIOExecutorService ();
20
17
21
18
private ProcessIOExecutorService () {
22
- super (1 , Integer .MAX_VALUE , 1 , TimeUnit .MINUTES , new SynchronousQueue <>(), new CountingThreadFactory () {
23
- @ NotNull
24
- @ Override
25
- public Thread newThread (@ NotNull final Runnable r ) {
26
- Thread thread = new Thread (r , POOLED_THREAD_PREFIX + counter .incrementAndGet ());
27
- thread .setPriority (Thread .NORM_PRIORITY - 1 );
28
- return thread ;
29
- }
30
- });
19
+ super (1 , Integer .MAX_VALUE , 1 , TimeUnit .MINUTES , new SynchronousQueue <>(), new MyCountingThreadFactory ());
31
20
}
32
21
33
22
@ TestOnly
34
23
public int getThreadCounter () {
35
24
return ((CountingThreadFactory )getThreadFactory ()).getCount ();
36
25
}
26
+
27
+ private static class MyCountingThreadFactory extends CountingThreadFactory {
28
+ // Ensure that we don't keep the classloader of the plugin which caused this thread to be created
29
+ // in Thread.inheritedAccessControlContext
30
+ private final ThreadFactory myThreadFactory = Executors .privilegedThreadFactory ();
31
+
32
+ @ NotNull
33
+ @ Override
34
+ public Thread newThread (@ NotNull final Runnable r ) {
35
+ Thread thread = myThreadFactory .newThread (r );
36
+ thread .setName (POOLED_THREAD_PREFIX + counter .incrementAndGet ());
37
+ thread .setPriority (Thread .NORM_PRIORITY - 1 );
38
+ return thread ;
39
+ }
40
+ }
37
41
}
0 commit comments