Skip to content

Commit a710c89

Browse files
committed
Change such that when testing the connection on return due to error it skips trimming connections
That is, when returning a connection that has errored and it tests the connection to ensure it is valid it WAS also trimming the connection pool and with this change it will not perform that trim. - Renames checkDataSource() -> heartBeat() - Splits out testConnection() to a separate method - Only call testConnection() in case of returning connection with forceClose (no trim here now)
1 parent b617559 commit a710c89

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ final class ConnectionPool implements DataSourcePool {
111111
this.pstmtCacheSize = params.getPstmtCacheSize();
112112
this.minConnections = params.getMinConnections();
113113
this.maxConnections = params.getMaxConnections();
114-
this.waitTimeoutMillis = params.getWaitTimeoutMillis();
115114
this.heartbeatsql = params.getHeartbeatSql();
115+
this.waitTimeoutMillis = params.getWaitTimeoutMillis();
116116
this.heartbeatFreqSecs = params.getHeartbeatFreqSecs();
117117
this.heartbeatTimeoutSeconds = params.getHeartbeatTimeoutSeconds();
118118
this.trimPoolFreqMillis = 1000L * params.getTrimPoolFreqSecs();
@@ -151,10 +151,10 @@ void pstmtCacheMetrics(PstmtCache pstmtCache) {
151151
pscRem.add(pstmtCache.removeCount());
152152
}
153153

154-
class HeartBeatRunnable extends TimerTask {
154+
final class HeartBeatRunnable extends TimerTask {
155155
@Override
156156
public void run() {
157-
checkDataSource();
157+
heartBeat();
158158
}
159159
}
160160

@@ -372,8 +372,12 @@ private void trimIdleConnections() {
372372
* This is called by the HeartbeatRunnable which should be scheduled to
373373
* run periodically (every heartbeatFreqSecs seconds).
374374
*/
375-
private void checkDataSource() {
375+
private void heartBeat() {
376376
trimIdleConnections();
377+
testConnection();
378+
}
379+
380+
private void testConnection() {
377381
Connection conn = null;
378382
try {
379383
// Get a connection from the pool and test it
@@ -561,7 +565,7 @@ private void returnTheConnection(PooledConnection pooledConnection, boolean forc
561565
queue.returnPooledConnection(pooledConnection, forceClose);
562566
if (forceClose) {
563567
// Got a bad connection so check the pool
564-
checkDataSource();
568+
testConnection();
565569
}
566570
}
567571

0 commit comments

Comments
 (0)