@@ -32,28 +32,33 @@ class AmqpEnvironment implements Environment {
32
32
private static final AtomicLong ID_SEQUENCE = new AtomicLong (0 );
33
33
34
34
private final Client client ;
35
- private final ExecutorService executorService ;
36
35
private final DefaultConnectionSettings <?> connectionSettings =
37
36
DefaultConnectionSettings .instance ();
38
37
private final AtomicBoolean closed = new AtomicBoolean (false );
39
38
private final boolean internalExecutor ;
40
39
private final boolean internalScheduledExecutor ;
40
+ private final boolean internalConsumerExecutor ;
41
+ private final boolean internalPublisherExecutor ;
42
+ private final ExecutorService executorService ;
43
+ private final ScheduledExecutorService scheduledExecutorService ;
44
+ private final ExecutorService publisherExecutorService ;
45
+ private final ExecutorService consumerExecutorService ;
41
46
private final ConnectionManager connectionManager = new ConnectionManager (this );
42
47
private final long id ;
43
48
private final Clock clock = new Clock ();
44
- private final ScheduledExecutorService scheduledExecutorService ;
45
49
private volatile ScheduledFuture <?> clockRefreshFuture ;
46
50
private final AtomicBoolean clockRefreshSet = new AtomicBoolean (false );
47
51
private final MetricsCollector metricsCollector ;
48
52
private final ObservationCollector observationCollector ;
49
53
private final ConnectionUtils .AffinityCache affinityCache = new ConnectionUtils .AffinityCache ();
50
54
private final EventLoop recoveryEventLoop ;
51
55
private final ExecutorService recoveryEventLoopExecutorService ;
52
- private final ExecutorService managementExecutorService ;
53
56
54
57
AmqpEnvironment (
55
58
ExecutorService executorService ,
56
59
ScheduledExecutorService scheduledExecutorService ,
60
+ ExecutorService publisherExecutorService ,
61
+ ExecutorService consumerExecutorService ,
57
62
DefaultConnectionSettings <?> connectionSettings ,
58
63
MetricsCollector metricsCollector ,
59
64
ObservationCollector observationCollector ) {
@@ -65,7 +70,7 @@ class AmqpEnvironment implements Environment {
65
70
66
71
String threadPrefix = String .format ("rabbitmq-amqp-environment-%d-" , this .id );
67
72
if (executorService == null ) {
68
- this .executorService = Utils .executorService (threadPrefix );
73
+ this .executorService = Executors . newCachedThreadPool ( Utils .threadFactory (threadPrefix ) );
69
74
this .internalExecutor = true ;
70
75
} else {
71
76
this .executorService = executorService ;
@@ -79,6 +84,21 @@ class AmqpEnvironment implements Environment {
79
84
this .scheduledExecutorService = scheduledExecutorService ;
80
85
this .internalScheduledExecutor = false ;
81
86
}
87
+ if (publisherExecutorService == null ) {
88
+ this .publisherExecutorService = Utils .executorService (threadPrefix );
89
+ this .internalPublisherExecutor = true ;
90
+ } else {
91
+ this .publisherExecutorService = publisherExecutorService ;
92
+ this .internalPublisherExecutor = false ;
93
+ }
94
+ if (consumerExecutorService == null ) {
95
+ this .consumerExecutorService =
96
+ Executors .newCachedThreadPool (Utils .threadFactory (threadPrefix + "consumer-" ));
97
+ this .internalConsumerExecutor = true ;
98
+ } else {
99
+ this .consumerExecutorService = consumerExecutorService ;
100
+ this .internalConsumerExecutor = false ;
101
+ }
82
102
this .metricsCollector =
83
103
metricsCollector == null ? NoOpMetricsCollector .INSTANCE : metricsCollector ;
84
104
this .observationCollector =
@@ -92,14 +112,6 @@ class AmqpEnvironment implements Environment {
92
112
new LinkedBlockingQueue <>(),
93
113
Utils .threadFactory (threadPrefix + "event-loop-" ));
94
114
this .recoveryEventLoop = new EventLoop (this .recoveryEventLoopExecutorService );
95
- this .managementExecutorService =
96
- new ThreadPoolExecutor (
97
- 0 ,
98
- Integer .MAX_VALUE ,
99
- 30 ,
100
- TimeUnit .SECONDS ,
101
- new SynchronousQueue <>(),
102
- Utils .threadFactory (threadPrefix + "management-loop-" ));
103
115
}
104
116
105
117
DefaultConnectionSettings <?> connectionSettings () {
@@ -111,6 +123,7 @@ Client client() {
111
123
}
112
124
113
125
Clock clock () {
126
+ // FIXME set clock on demand
114
127
if (this .clockRefreshSet .compareAndSet (false , true )) {
115
128
this .clockRefreshFuture =
116
129
this .scheduledExecutorService .scheduleAtFixedRate (
@@ -126,13 +139,18 @@ public void close() {
126
139
this .client .close ();
127
140
this .recoveryEventLoop .close ();
128
141
this .recoveryEventLoopExecutorService .shutdownNow ();
129
- this .managementExecutorService .shutdownNow ();
130
142
if (this .internalExecutor ) {
131
143
this .executorService .shutdownNow ();
132
144
}
133
145
if (this .internalScheduledExecutor ) {
134
146
this .scheduledExecutorService .shutdownNow ();
135
147
}
148
+ if (this .internalPublisherExecutor ) {
149
+ this .publisherExecutorService .shutdownNow ();
150
+ }
151
+ if (this .internalConsumerExecutor ) {
152
+ this .consumerExecutorService .shutdownNow ();
153
+ }
136
154
if (this .clockRefreshFuture != null ) {
137
155
this .clockRefreshFuture .cancel (false );
138
156
}
@@ -149,8 +167,12 @@ ExecutorService executorService() {
149
167
return this .executorService ;
150
168
}
151
169
152
- ExecutorService managementExecutorService () {
153
- return this .managementExecutorService ;
170
+ ExecutorService publisherExecutorService () {
171
+ return this .publisherExecutorService ;
172
+ }
173
+
174
+ ExecutorService consumerExecutorService () {
175
+ return this .consumerExecutorService ;
154
176
}
155
177
156
178
ScheduledExecutorService scheduledExecutorService () {
0 commit comments