Skip to content

Commit f973ff2

Browse files
committed
Merge pull request AsyncHttpClient#24 from rlubke/master
Small perf change. See commits for details.
2 parents b2ff86b + efe60cb commit f973ff2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
import java.io.UnsupportedEncodingException;
9797
import java.net.InetSocketAddress;
9898
import java.net.URI;
99-
import java.net.URL;
10099
import java.net.URLEncoder;
101100
import java.nio.ByteBuffer;
102101
import java.security.NoSuchAlgorithmException;

src/main/java/com/ning/http/client/providers/grizzly/GrizzlyConnectionsPool.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ final class IdleConnectionQueue {
360360

361361
final TimeoutResolver resolver = new TimeoutResolver();
362362
final long timeout;
363+
final AtomicInteger count = new AtomicInteger(0);
363364

364365
// ---------------------------------------------------- Constructors
365366

@@ -377,9 +378,11 @@ void offer(final Connection c) {
377378
resolver.setTimeoutMs(c, System.currentTimeMillis() + timeout);
378379
}
379380
queue.offer(c);
381+
count.incrementAndGet();
380382
}
381383

382384
Connection poll() {
385+
count.decrementAndGet();
383386
return queue.poll();
384387
}
385388

@@ -388,15 +391,16 @@ boolean remove(final Connection c) {
388391
resolver.removeTimeout(c);
389392

390393
}
394+
count.decrementAndGet();
391395
return queue.remove(c);
392396
}
393397

394398
int size() {
395-
return queue.size();
399+
return count.get();
396400
}
397401

398402
boolean isEmpty() {
399-
return queue.isEmpty();
403+
return (count.get() == 0);
400404
}
401405

402406
void destroy() {

0 commit comments

Comments
 (0)