@@ -93,6 +93,7 @@ public class ChannelManager {
9393 private final boolean maxConnectionsPerHostEnabled ;
9494 private final ConcurrentHashMapV8 <Object , Semaphore > freeChannelsPerHost ;
9595 private final ConcurrentHashMapV8 <Integer , Object > channelId2PartitionKey ;
96+ private final ConcurrentHashMapV8 .Fun <Object , Semaphore > semaphoreComputer ;
9697 private final long handshakeTimeout ;
9798 private final Timer nettyTimer ;
9899 private final IOException tooManyConnections ;
@@ -108,7 +109,7 @@ public class ChannelManager {
108109
109110 private Processor wsProcessor ;
110111
111- public ChannelManager (AsyncHttpClientConfig config , NettyAsyncHttpProviderConfig nettyConfig , Timer nettyTimer ) {
112+ public ChannelManager (final AsyncHttpClientConfig config , NettyAsyncHttpProviderConfig nettyConfig , Timer nettyTimer ) {
112113
113114 this .config = config ;
114115 this .nettyConfig = nettyConfig ;
@@ -157,9 +158,17 @@ public boolean remove(Object o) {
157158 if (maxConnectionsPerHostEnabled ) {
158159 freeChannelsPerHost = new ConcurrentHashMapV8 <>();
159160 channelId2PartitionKey = new ConcurrentHashMapV8 <>();
161+ semaphoreComputer = new ConcurrentHashMapV8 .Fun <Object , Semaphore >() {
162+ @ Override
163+ public Semaphore apply (Object partitionKey ) {
164+ return new Semaphore (config .getMaxConnectionsPerHost ());
165+ }
166+ };
167+
160168 } else {
161169 freeChannelsPerHost = null ;
162170 channelId2PartitionKey = null ;
171+ semaphoreComputer = null ;
163172 }
164173
165174 handshakeTimeout = nettyConfig .getHandshakeTimeout ();
@@ -308,13 +317,6 @@ private boolean tryAcquireGlobal() {
308317 return !maxTotalConnectionsEnabled || freeChannels .tryAcquire ();
309318 }
310319
311- private final ConcurrentHashMapV8 .Fun <Object , Semaphore > semaphoreComputer = new ConcurrentHashMapV8 .Fun <Object , Semaphore >() {
312- @ Override
313- public Semaphore apply (Object partitionKey ) {
314- return new Semaphore (config .getMaxConnectionsPerHost ());
315- }
316- };
317-
318320 private Semaphore getFreeConnectionsForHost (Object partitionKey ) {
319321 return freeChannelsPerHost .computeIfAbsent (partitionKey , semaphoreComputer );
320322 }
0 commit comments