你好。我用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()当数据库连接发生错误时第二次获取时间太长
(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()当数据库连接发生错误时第二次获取时间太长
解决方案 »
- jsp链接数据库,tomcat不会报错,帮看看哪里错了
- easyui tree checkbox的选中状态
- 我是用JSP做网站的,用的是spring+hibernate.想结实一下从事java工作的同行,互相研究.qq:546073527
- 以excel格式打开文件
- 用installanywhere打包jsp的 问题
- 关于cookie
- 求救简繁字体转换
- Ibatis SQL性能求助
- 在Action中如何得到Form的全部值,一共涉及到3个table大约有30来个字段
- CJEAstruts研讨会中的例子,jdk开发struts的FormBean和ActionBean报错?(另一问)
- datagrid高度自适应问题
- 如何通过post请求获取知乎的登录信息
解决方法:当连接发生错误时,必须要重新初始化数据源。