2626import java .util .HashMap ;
2727import java .util .Map ;
2828import java .util .concurrent .CopyOnWriteArrayList ;
29+ import java .util .concurrent .ExecutorService ;
2930import java .util .concurrent .TimeoutException ;
3031
3132import com .rabbitmq .client .AMQP ;
@@ -62,6 +63,7 @@ final class Copyright {
6263public class AMQConnection extends ShutdownNotifierComponent implements Connection , NetworkConnection {
6364 /** Timeout used while waiting for AMQP handshaking to complete (milliseconds) */
6465 public static final int HANDSHAKE_TIMEOUT = 10000 ;
66+ private final ExecutorService executor ;
6567 private Thread mainLoopThread ;
6668 private ThreadFactory threadFactory = new DefaultThreadFactory ();
6769
@@ -104,7 +106,7 @@ public static final Map<String, Object> defaultClientProperties() {
104106 }
105107 };
106108
107- protected final ConsumerWorkService _workService ;
109+ protected ConsumerWorkService _workService = null ;
108110
109111 /** Frame source/sink */
110112 private final FrameHandler _frameHandler ;
@@ -215,17 +217,21 @@ public AMQConnection(ConnectionParams params, FrameHandler frameHandler)
215217 this .requestedChannelMax = params .getRequestedChannelMax ();
216218 this .requestedHeartbeat = params .getRequestedHeartbeat ();
217219 this .saslConfig = params .getSaslConfig ();
220+ this .executor = params .getExecutor ();
218221
219- this ._workService = new ConsumerWorkService (params .getExecutor ());
220222 this ._channelManager = null ;
221223
222224 this ._brokerInitiatedShutdown = false ;
223225
224226 this ._inConnectionNegotiation = true ; // we start out waiting for the first protocol response
225227 }
226228
227- private void initializeHeartbeatSender (FrameHandler frameHandler ) {
228- this ._heartbeatSender = new HeartbeatSender (frameHandler , threadFactory );
229+ private void initializeConsumerWorkService () {
230+ this ._workService = new ConsumerWorkService (executor , threadFactory );
231+ }
232+
233+ private void initializeHeartbeatSender () {
234+ this ._heartbeatSender = new HeartbeatSender (_frameHandler , threadFactory );
229235 }
230236
231237 /**
@@ -247,7 +253,8 @@ private void initializeHeartbeatSender(FrameHandler frameHandler) {
247253 public void start ()
248254 throws IOException
249255 {
250- initializeHeartbeatSender (_frameHandler );
256+ initializeConsumerWorkService ();
257+ initializeHeartbeatSender ();
251258 this ._running = true ;
252259 // Make sure that the first thing we do is to send the header,
253260 // which should cause any socket errors to show up for us, rather
0 commit comments