Skip to content

Commit faeb084

Browse files
committed
Allow connection pool to grow
1 parent e0d868d commit faeb084

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

ebean-datasource/src/main/java/io/ebean/datasource/pool/ConnectionBuffer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@
120120
*/
121121
final class ConnectionBuffer {
122122

123+
static final Object POP_LAST = new Object();
124+
123125
private final Node free = Node.init();
124126
private final Node freeEnd = free.next;
125127
private final Node busy = Node.init();
@@ -218,13 +220,14 @@ PooledConnection popFree(Object affinityId) {
218220
Node node;
219221
if (affinityId == null || affinityNodes == null) {
220222
node = free.next;
223+
} else if (affinityId == POP_LAST) {
224+
node = freeEnd.prev;
221225
} else {
222226
node = affinityNodes[affinityId.hashCode() % hashSize].find(affinityId);
223227
if (node == null) {
224-
// when we did not find a node with that affinity, we take the last (oldest one)
225-
// and reuse this with the new affinity. This avoids to "steal" the affinity
226-
// from the newest one.
227-
node = freeEnd.prev;
228+
// when we did not find a node with that affinity, we return null
229+
// this allows the pool to grow to its maximum size
230+
return null;
228231
}
229232
}
230233
if (node.isBoundaryNode()) {

ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,19 @@ private PooledConnection _obtainConnection(Object affinitiyId) throws Interrupte
231231
if (connection != null) {
232232
return connection;
233233
}
234+
if (affinitiyId != null) {
235+
connection = extractFromFreeList(ConnectionBuffer.POP_LAST);
236+
if (connection != null) {
237+
return connection;
238+
}
239+
}
234240
}
235241
try {
236242
// The pool is at maximum size. We are going to go into
237243
// a wait loop until connections are returned into the pool.
238244
waitCount++;
239245
waitingThreads++;
240-
return _obtainConnectionWaitLoop(affinitiyId);
246+
return _obtainConnectionWaitLoop(null);
241247
} finally {
242248
waitingThreads--;
243249
}

0 commit comments

Comments
 (0)