Skip to content

Commit f32f897

Browse files
authored
Merge pull request #95 from ebean-orm/feature/heartBeat-1
Change such that when testing the connection on return due to error it skips trimming connections
2 parents b617559 + a710c89 commit f32f897

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)