mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修正evict的bug
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@520 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -19,6 +19,7 @@ import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -699,16 +700,16 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
if (numTestsPerEvictionRun <= 0) {
|
||||
numTestsPerEvictionRun = 1;
|
||||
}
|
||||
|
||||
|
||||
final int testCount;
|
||||
if (numTestsPerEvictionRun <= count) {
|
||||
testCount = numTestsPerEvictionRun;
|
||||
} else {
|
||||
testCount = count;
|
||||
}
|
||||
|
||||
for (int i = 0; i < testCount; ++i) {
|
||||
for (int i = 0;; ++i) {
|
||||
if (i >= count) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (idleList.size() >= numTestsPerEvictionRun) {
|
||||
break;
|
||||
}
|
||||
|
||||
ConnectionHolder connection = connections[i];
|
||||
|
||||
if (evictCount == 0 && idleCount == 0 && connection == null) {
|
||||
@@ -722,10 +723,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
idleList.add(connection);
|
||||
}
|
||||
}
|
||||
System.arraycopy(connections, testCount, connections, 0, count - testCount);
|
||||
for (int i = 0; i < testCount; ++i) {
|
||||
connections[--count] = null;
|
||||
}
|
||||
int removeCount = idleList.size() + evictList.size();
|
||||
System.arraycopy(connections, removeCount, connections, 0, count - removeCount);
|
||||
Arrays.fill(connections, count - removeCount, count, null);
|
||||
count -= removeCount;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CaseKylin_mysql_idle extends TestCase {
|
||||
p0(dataSource, "druid", threadCount);
|
||||
|
||||
long startMillis = System.currentTimeMillis();
|
||||
for (int i = 0; i < TEST_COUNT; ++i) {
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
p0(dataSource, "druid", threadCount);
|
||||
|
||||
long seconds = (System.currentTimeMillis() - startMillis) / 1000L;
|
||||
|
||||
+6
-6
@@ -12,20 +12,20 @@ import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
public class TestIdle extends TestCase {
|
||||
public class TestIdleForKylin extends TestCase {
|
||||
|
||||
public void test_idle() throws Exception {
|
||||
MockDriver driver = MockDriver.instance;
|
||||
|
||||
BasicDataSource dataSource = new BasicDataSource();
|
||||
// DruidDataSource dataSource = new DruidDataSource();
|
||||
// BasicDataSource dataSource = new BasicDataSource();
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setDriverClassName("com.alibaba.druid.mock.MockDriver");
|
||||
dataSource.setInitialSize(1);
|
||||
dataSource.setMaxActive(5);
|
||||
dataSource.setMaxIdle(5);
|
||||
dataSource.setMaxActive(10);
|
||||
dataSource.setMaxIdle(10);
|
||||
dataSource.setMinIdle(0);
|
||||
dataSource.setMinEvictableIdleTimeMillis(5000 * 1);
|
||||
dataSource.setMinEvictableIdleTimeMillis(50000 * 1);
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(500);
|
||||
dataSource.setTestWhileIdle(true);
|
||||
dataSource.setTestOnBorrow(false);
|
||||
Reference in New Issue
Block a user