Skip to content

Commit 3097392

Browse files
author
Stephane Landelle
committed
IdleChannelDetector should remove empty queues, close AsyncHttpClient#676
1 parent acb49bd commit 3097392

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/com/ning/http/client/providers/netty/channel/pool/DefaultChannelPool.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.ArrayList;
3030
import java.util.Collections;
3131
import java.util.List;
32+
import java.util.Map;
3233
import java.util.concurrent.ConcurrentHashMap;
3334
import java.util.concurrent.ConcurrentLinkedQueue;
3435
import java.util.concurrent.TimeUnit;
@@ -194,15 +195,21 @@ public void run(Timeout timeout) throws Exception {
194195
int closedCount = 0;
195196
int totalCount = 0;
196197

197-
for (ConcurrentLinkedQueue<IdleChannel> pool : poolsPerKey.values()) {
198+
for (Map.Entry<String, ConcurrentLinkedQueue<IdleChannel>> entry : poolsPerKey.entrySet()) {
199+
200+
String poolKey = entry.getKey();
201+
ConcurrentLinkedQueue<IdleChannel> pool = entry.getValue();
202+
198203
// store in intermediate unsynchronized lists to minimize the impact on the ConcurrentLinkedQueue
199204
if (LOGGER.isDebugEnabled())
200205
totalCount += pool.size();
201206

202207
List<IdleChannel> closedChannels = closeChannels(expiredChannels(pool, start));
208+
203209
pool.removeAll(closedChannels);
204-
int poolClosedCount = closedChannels.size();
205-
closedCount += poolClosedCount;
210+
closedCount += closedChannels.size();
211+
if (pool.isEmpty())
212+
poolsPerKey.remove(poolKey);
206213
}
207214

208215
long duration = millisTime() - start;

0 commit comments

Comments
 (0)