22
22
import org .jetbrains .annotations .NotNull ;
23
23
24
24
import javax .swing .*;
25
- import java .util .concurrent .CountDownLatch ;
26
- import java .util .concurrent .ExecutionException ;
27
- import java .util .concurrent .Executor ;
28
- import java .util .concurrent .ExecutorService ;
29
- import java .util .concurrent .Executors ;
30
- import java .util .concurrent .Future ;
31
- import java .util .concurrent .SynchronousQueue ;
32
- import java .util .concurrent .ThreadPoolExecutor ;
33
- import java .util .concurrent .TimeUnit ;
34
- import java .util .concurrent .TimeoutException ;
25
+ import java .util .concurrent .*;
35
26
import java .util .concurrent .atomic .AtomicReference ;
36
27
37
28
/**
@@ -43,32 +34,35 @@ public final class Schedulers {
43
34
private Schedulers () {
44
35
}
45
36
46
- private static volatile ExecutorService CACHED_EXECUTOR ;
37
+ private static volatile ThreadPoolExecutor CACHED_EXECUTOR ;
47
38
48
- public static synchronized Executor newThread () {
39
+ public static synchronized ThreadPoolExecutor newThread () {
49
40
if (CACHED_EXECUTOR == null )
50
41
CACHED_EXECUTOR = new ThreadPoolExecutor (0 , Integer .MAX_VALUE ,
51
42
60 , TimeUnit .SECONDS , new SynchronousQueue <>(), Executors .defaultThreadFactory ());
52
43
53
44
return CACHED_EXECUTOR ;
54
45
}
55
46
56
- private static volatile ExecutorService IO_EXECUTOR ;
47
+ private static volatile ThreadPoolExecutor IO_EXECUTOR ;
57
48
58
- public static synchronized Executor io () {
49
+ public static synchronized ThreadPoolExecutor io () {
59
50
if (IO_EXECUTOR == null )
60
- IO_EXECUTOR = Executors .newFixedThreadPool (6 , runnable -> {
61
- Thread thread = Executors .defaultThreadFactory ().newThread (runnable );
62
- thread .setDaemon (true );
63
- return thread ;
64
- });
51
+ IO_EXECUTOR = new ThreadPoolExecutor (0 , 6 ,
52
+ 60L , TimeUnit .SECONDS ,
53
+ new SynchronousQueue <>(),
54
+ runnable -> {
55
+ Thread thread = Executors .defaultThreadFactory ().newThread (runnable );
56
+ thread .setDaemon (true );
57
+ return thread ;
58
+ });
65
59
66
60
return IO_EXECUTOR ;
67
61
}
68
62
69
63
private static volatile ExecutorService SINGLE_EXECUTOR ;
70
64
71
- public static synchronized Executor computation () {
65
+ public static synchronized ExecutorService computation () {
72
66
if (SINGLE_EXECUTOR == null )
73
67
SINGLE_EXECUTOR = Executors .newSingleThreadExecutor (runnable -> {
74
68
Thread thread = Executors .defaultThreadFactory ().newThread (runnable );
0 commit comments