HTTPCLIENT-1108: reuse of persistent connections now uses a stack (LIFO)
instead of a queue (FIFO), so that unneeded connections will eventually become idle and reclaimable by closeIdleConnections(). git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1147280 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d5b66aa9d8
commit
8600a7e959
|
@ -34,6 +34,7 @@ import java.util.Queue;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -82,7 +83,7 @@ public class ConnPoolByRoute extends AbstractConnPool { //TODO: remove dependenc
|
||||||
protected final Set<BasicPoolEntry> leasedConnections;
|
protected final Set<BasicPoolEntry> leasedConnections;
|
||||||
|
|
||||||
/** The list of free connections */
|
/** The list of free connections */
|
||||||
protected final Queue<BasicPoolEntry> freeConnections;
|
protected final Stack<BasicPoolEntry> freeConnections;
|
||||||
|
|
||||||
/** The list of WaitingThreads waiting for a connection */
|
/** The list of WaitingThreads waiting for a connection */
|
||||||
protected final Queue<WaitingThread> waitingThreads;
|
protected final Queue<WaitingThread> waitingThreads;
|
||||||
|
@ -162,8 +163,8 @@ public class ConnPoolByRoute extends AbstractConnPool { //TODO: remove dependenc
|
||||||
*
|
*
|
||||||
* @return a queue
|
* @return a queue
|
||||||
*/
|
*/
|
||||||
protected Queue<BasicPoolEntry> createFreeConnQueue() {
|
protected Stack<BasicPoolEntry> createFreeConnQueue() {
|
||||||
return new LinkedList<BasicPoolEntry>();
|
return new Stack<BasicPoolEntry>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -462,7 +463,7 @@ public class ConnPoolByRoute extends AbstractConnPool { //TODO: remove dependenc
|
||||||
}
|
}
|
||||||
rospl.freeEntry(entry);
|
rospl.freeEntry(entry);
|
||||||
entry.updateExpiry(validDuration, timeUnit);
|
entry.updateExpiry(validDuration, timeUnit);
|
||||||
freeConnections.add(entry);
|
freeConnections.push(entry);
|
||||||
} else {
|
} else {
|
||||||
rospl.dropEntry();
|
rospl.dropEntry();
|
||||||
numConnections--;
|
numConnections--;
|
||||||
|
@ -611,7 +612,7 @@ public class ConnPoolByRoute extends AbstractConnPool { //TODO: remove dependenc
|
||||||
poolLock.lock();
|
poolLock.lock();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
BasicPoolEntry entry = freeConnections.remove();
|
BasicPoolEntry entry = freeConnections.pop();
|
||||||
|
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
deleteEntry(entry);
|
deleteEntry(entry);
|
||||||
|
|
Loading…
Reference in New Issue