2525import java .util .concurrent .TimeUnit ;
2626
2727import com .rabbitmq .client .ShutdownSignalException ;
28+ import com .rabbitmq .client .ThreadFactory ;
2829import com .rabbitmq .utility .IntAllocator ;
2930
3031/**
@@ -45,12 +46,17 @@ public final class ChannelManager {
4546
4647 /** Maximum channel number available on this connection. */
4748 private final int _channelMax ;
49+ private final ThreadFactory threadFactory ;
4850
4951 public int getChannelMax (){
5052 return _channelMax ;
5153 }
5254
5355 public ChannelManager (ConsumerWorkService workService , int channelMax ) {
56+ this (workService , channelMax , new DefaultThreadFactory ());
57+ }
58+
59+ public ChannelManager (ConsumerWorkService workService , int channelMax , ThreadFactory threadFactory ) {
5460 if (channelMax == 0 ) {
5561 // The framing encoding only allows for unsigned 16-bit integers
5662 // for the channel number
@@ -60,6 +66,7 @@ public ChannelManager(ConsumerWorkService workService, int channelMax) {
6066 channelNumberAllocator = new IntAllocator (1 , channelMax );
6167
6268 this .workService = workService ;
69+ this .threadFactory = threadFactory ;
6370 }
6471
6572 /**
@@ -97,13 +104,18 @@ public void handleSignal(ShutdownSignalException signal) {
97104 private void scheduleShutdownProcessing () {
98105 final Set <CountDownLatch > sdSet = new HashSet <CountDownLatch >(shutdownSet );
99106 final ConsumerWorkService ssWorkService = workService ;
100- Thread shutdownThread = new Thread ( new Runnable () {
107+ Runnable target = new Runnable () {
101108 public void run () {
102109 for (CountDownLatch latch : sdSet ) {
103- try { latch .await (SHUTDOWN_TIMEOUT_SECONDS , TimeUnit .SECONDS ); } catch (Throwable e ) { }
110+ try {
111+ latch .await (SHUTDOWN_TIMEOUT_SECONDS , TimeUnit .SECONDS );
112+ } catch (Throwable e ) {
113+ }
104114 }
105115 ssWorkService .shutdown ();
106- }}, "ConsumerWorkServiceShutdown" );
116+ }
117+ };
118+ Thread shutdownThread = threadFactory .newThread (target , "ConsumerWorkService shutdown monitor" );
107119 shutdownThread .setDaemon (true );
108120 shutdownThread .start ();
109121 }
0 commit comments