|
14 | 14 | package org.asynchttpclient.providers.netty.channel.pool;
|
15 | 15 |
|
16 | 16 | import static org.asynchttpclient.util.DateUtils.millisTime;
|
17 |
| - |
18 |
| -import org.asynchttpclient.AsyncHttpClientConfig; |
19 |
| -import org.asynchttpclient.providers.netty.channel.Channels; |
20 |
| -import org.asynchttpclient.providers.netty.future.NettyResponseFuture; |
21 |
| -import org.slf4j.Logger; |
22 |
| -import org.slf4j.LoggerFactory; |
23 |
| - |
24 | 17 | import io.netty.channel.Channel;
|
25 | 18 | import io.netty.util.Timeout;
|
26 | 19 | import io.netty.util.Timer;
|
|
29 | 22 | import java.util.ArrayList;
|
30 | 23 | import java.util.Collections;
|
31 | 24 | import java.util.List;
|
| 25 | +import java.util.Map; |
32 | 26 | import java.util.concurrent.ConcurrentHashMap;
|
33 | 27 | import java.util.concurrent.ConcurrentLinkedQueue;
|
34 | 28 | import java.util.concurrent.TimeUnit;
|
35 | 29 | import java.util.concurrent.atomic.AtomicBoolean;
|
36 | 30 |
|
| 31 | +import org.asynchttpclient.AsyncHttpClientConfig; |
| 32 | +import org.asynchttpclient.providers.netty.channel.Channels; |
| 33 | +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; |
| 34 | +import org.slf4j.Logger; |
| 35 | +import org.slf4j.LoggerFactory; |
| 36 | + |
37 | 37 | /**
|
38 | 38 | * A simple implementation of {@link com.ning.http.client.providers.netty.pool.ChannelPool} based on a {@link java.util.concurrent.ConcurrentHashMap}
|
39 | 39 | */
|
@@ -198,15 +198,19 @@ public void run(Timeout timeout) throws Exception {
|
198 | 198 | int closedCount = 0;
|
199 | 199 | int totalCount = 0;
|
200 | 200 |
|
201 |
| - for (ConcurrentLinkedQueue<IdleChannel> pool : poolsPerKey.values()) { |
| 201 | + for (Map.Entry<String, ConcurrentLinkedQueue<IdleChannel>> entry : poolsPerKey.entrySet()) { |
| 202 | + |
| 203 | + String poolKey = entry.getKey(); |
| 204 | + ConcurrentLinkedQueue<IdleChannel> pool = entry.getValue(); |
202 | 205 | // store in intermediate unsynchronized lists to minimize the impact on the ConcurrentLinkedQueue
|
203 | 206 | if (LOGGER.isDebugEnabled())
|
204 | 207 | totalCount += pool.size();
|
205 | 208 |
|
206 | 209 | List<IdleChannel> closedChannels = closeChannels(expiredChannels(pool, start));
|
207 | 210 | pool.removeAll(closedChannels);
|
208 |
| - int poolClosedCount = closedChannels.size(); |
209 |
| - closedCount += poolClosedCount; |
| 211 | + closedCount += closedChannels.size(); |
| 212 | + if (pool.isEmpty()) |
| 213 | + poolsPerKey.remove(poolKey); |
210 | 214 | }
|
211 | 215 |
|
212 | 216 | long duration = millisTime() - start;
|
|
0 commit comments