durid连接池获取连接的时间太长
你好。我用servlet通过配置文件获取durid连接池中连接,在这里,我的数据库密码错误的情况下,每次都是第一次从连接池中取connection时很快,但第二次取connection时很慢,原因何在?
(1)连接池的部分配置:
initialSize = 10
maxActive = 100
minIdle = 3
maxWait = 10000
removeAbandoned = true
removeAbandonedTimeout = 180
timeBetweenEvictionRunsMillis = 20000
minEvictableIdleTimeMillis = 50000
validationQuery = SELECT 1 FROM DUAL
testWhileIdle = true
testOnBorrow = false
testOnReturn = false
poolPreparedStatements = false
maxPoolPreparedStatementPerConnectionSize = 50
filters =stat
(2)数据源的创建
/**
* 初始化连接 dataSource
*
* @param ConfigName
*/
public static void initdataSource(Properties ps) {
try {
dataSource = DruidDataSourceFactory.createDataSource(ps);
}
catch (Exception e) {
e.printStackTrace();
}
}
(3)连接的获取
public static Connection getConnection() throws Exception {
try {
return dataSource.getConnection();
} catch (GetConnectionTimeoutException e) {
throw new Exception("数据库连接有问题,连接超时!", e);
}catch (SQLException e) {
throw new Exception("数据库连接有问题,账号或密码错误!", e);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
我的瓶颈就是在dataSource.getConnection()当数据库连接发生错误时第二次获取时间太长