bug fixed for "timeBetweenEvictionRunsMillis > keepAliveBetweenTimeMillis"

This commit is contained in:
高铁
2021-04-19 13:55:13 +08:00
parent 1d5ae7929d
commit 71a1b40a4e
4 changed files with 17 additions and 7 deletions
@@ -790,6 +790,10 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
LOG.error("keepAliveBetweenTimeMillis should be greater than 30000");
}
if (keepAliveBetweenTimeMillis <= timeBetweenEvictionRunsMillis) {
LOG.warn("keepAliveBetweenTimeMillis should be greater than timeBetweenEvictionRunsMillis");
}
this.keepAliveBetweenTimeMillis = keepAliveBetweenTimeMillis;
}
@@ -870,6 +870,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
throw new SQLException("maxEvictableIdleTimeMillis must be grater than minEvictableIdleTimeMillis");
}
if (keepAlive && keepAliveBetweenTimeMillis <= timeBetweenEvictionRunsMillis) {
throw new SQLException("keepAliveBetweenTimeMillis must be grater than timeBetweenEvictionRunsMillis");
}
if (this.driverClass != null) {
this.driverClass = driverClass.trim();
}
@@ -2864,7 +2868,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
for (;;) {
// 从前面开始删除
try {
if (closed) {
if (closed || closing) {
break;
}
@@ -165,7 +165,9 @@ public class DruidDataSourceC3P0Adapter implements DataSource, DruidDataSourceC3
}
public void setIdleConnectionTestPeriod(int idleConnectionTestPeriod) {
dataSource.setTimeBetweenEvictionRunsMillis(((long) idleConnectionTestPeriod) * 1000L);
long timeBetweenEvictionRunsMillis = ((long) idleConnectionTestPeriod) * 1000L;
dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
dataSource.setKeepAliveBetweenTimeMillis(timeBetweenEvictionRunsMillis * 2);
}
public int getInitialPoolSize() {
@@ -37,9 +37,12 @@ public class KeepAliveTest extends TestCase {
public void test_keepAlive() throws Exception {
dataSource.init();
for (int i = 0; i < 1000; ++i) {
if (dataSource.getMinIdle() == dataSource.getPoolingCount()) {
for (int i = 0; i < 100; ++i) {
int poolingCount = dataSource.getPoolingCount();
if (poolingCount >= dataSource.getMinIdle()) {
break;
} else {
System.out.println("poolingCount : " + poolingCount);
}
Thread.sleep(10 * 1);
}
@@ -55,8 +58,5 @@ public class KeepAliveTest extends TestCase {
}
// assertEquals(dataSource.getMaxActive(), dataSource.getPoolingCount());
Thread.sleep(1000 * 1000);
}
}