查看catalina.out日志出现错误Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.borrowObject(Gener
icObjectPool.java:1134)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDa
taSource.java:96)
... 20 more
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool er
ror Timeout waiting for idle object
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDa
taSource.java:104)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSo
urce.java:880)
我的server.xml配置如下(采用连接池)<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="1000" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<Host name="myweb.com" debug="0" appBase="/opt/vhosts/myweb.com" autoDep
loy="true">
<Context path="" docBase="/opt/vhosts/myweb.com" debug="0" reloadab
le="true">
<Logger className="org.apache.catalina.logger.FileLogger" directory="log
s" prefix="web_log." suffix=".txt" timestamp="true"/>
<Resource name="jdbc/mmclick" auth="Container" scope="Shareable" type="j
avax.sql.DataSource" maxActive="1000" maxIdle="1000" maxWait="10000" username="m
xxx" password="xxx" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mys
ql://localhost/mydb?autoReconnect=true"/>
</Context>
</Host>
请高手指点错误,我的网站只是一个JSP文件,至少关闭连接代码已经有 finally
{
try
{
if(null!=rss){
rss.close();
rss=null;
}
if(null!=rs){
rs.close();
rs=null;
}
if(null!=pstmt){
pstmt.close();
pstmt=null;
}
if(null !=pstmt1){
pstmt1.close();
pstmt1=null;
}
if(null!=conn){
conn.close();
conn=null;
}
}
catch (Exception e) {
conn=null;
}
}
at org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.borrowObject(Gener
icObjectPool.java:1134)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDa
taSource.java:96)
... 20 more
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool er
ror Timeout waiting for idle object
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDa
taSource.java:104)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSo
urce.java:880)
我的server.xml配置如下(采用连接池)<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="1000" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<Host name="myweb.com" debug="0" appBase="/opt/vhosts/myweb.com" autoDep
loy="true">
<Context path="" docBase="/opt/vhosts/myweb.com" debug="0" reloadab
le="true">
<Logger className="org.apache.catalina.logger.FileLogger" directory="log
s" prefix="web_log." suffix=".txt" timestamp="true"/>
<Resource name="jdbc/mmclick" auth="Container" scope="Shareable" type="j
avax.sql.DataSource" maxActive="1000" maxIdle="1000" maxWait="10000" username="m
xxx" password="xxx" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mys
ql://localhost/mydb?autoReconnect=true"/>
</Context>
</Host>
请高手指点错误,我的网站只是一个JSP文件,至少关闭连接代码已经有 finally
{
try
{
if(null!=rss){
rss.close();
rss=null;
}
if(null!=rs){
rs.close();
rs=null;
}
if(null!=pstmt){
pstmt.close();
pstmt=null;
}
if(null !=pstmt1){
pstmt1.close();
pstmt1=null;
}
if(null!=conn){
conn.close();
conn=null;
}
}
catch (Exception e) {
conn=null;
}
}
Web程序在tomcat刚开始运行时速度很快,但过一段时间后发现速度变得很慢。
检查日志输出,发现异常如下:
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted, cause:
java.util.NoSuchElementException: Timeout waiting for idle object
同时在SQLServer事件探查器中发现,每执行一次sql语句都要产生Audit login事件,语句执行后产生
Audit logout事件。说明每一次tomcat都是重新打开新的连接。
2 问题解决
tomcat 的数据源定义提供了三个参数:
a. 如果设为true则tomcat自动检查恢复重新利用,没有正常关闭的Connection.(默认是false)
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
b. 设定连接在多少秒内被认为是放弃的连接,即可进行恢复利用。
<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>
c. 输出回收的日志,可以详细打印出异常从而发现是在那里发生了泄漏
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>