在线求助 Tomcat如何自动关闭数据库连接池的连接
xfyyw
|
1#
xfyyw 发表于 2007-06-09 16:09
在线求助 Tomcat如何自动关闭数据库连接池的连接
我的服务器是Tomcat 5.0.28,其中数据库连接池的配置文件如下:
<Context debug= "1 " displayName= "WebRoot " docBase= "WebRoot " path= "/ " reloadable= "true "> <Resource auth= "Container " name= "jdbc/connectDB " type= "javax.sql.DataSource "/> <ResourceParams name= "jdbc/connectDB "> <parameter> <name> factory </name> <value> org.apache.commons.dbcp.BasicDataSourceFactory </value> </parameter> <parameter> <name> url </name> <value> jdbc:microsoft:sqlserver://localhost:1433;databasename=zgws </value> </parameter> <parameter> <name> maxWait </name> <value> 5000 </value> </parameter> <parameter> <name> maxActive </name> <value> 200 </value> </parameter> <parameter> <name> driverClassName </name> <value> com.microsoft.jdbc.sqlserver.SQLServerDriver </value> </parameter> <parameter> <name> maxIdle </name> <value> 20 </value> </parameter> <parameter> <name> username </name> <value> sa </value> </parameter> <parameter> <name> password </name> <value> ****** </value> </parameter> <parameter> <name> removeAbandoned </name> <value> true </value> </parameter> <parameter> <name> removeAbandonedTimeout </name> <value> 10 </value> </parameter> <parameter> <name> logAbandoned </name> <value> true </value> </parameter> </ResourceParams> </Context> 在这个配置文件中removeAbandoned设定了自动关闭连接,但是Tomcat服务器没有自动关闭连接,当连接数超过200个时,报如下的错误: DBCP object created 2007-06-07 11:01:28 by the following code was never closed: java.lang.Exception at org.apache.commons.dbcp.AbandonedTrace.init(AbandonedTrace.java:96) at org.apache.commons.dbcp.AbandonedTrace. <init> (AbandonedTrace.java:79) at org.apache.commons.dbcp.DelegatingStatement. <init> (DelegatingStatement.java:60) at org.apache.commons.dbcp.DelegatingConnection.createStatement(DelegatingConnection.java:173) at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.createStatement(PoolingDataSource.java:209) at operate.DBOperate.PoolConnect(DBOperate.java:143) at operate.DBOperate.Connect(DBOperate.java:79) at dao.init.index.IndexINIT. <init> (IndexINIT.java:31) at org.apache.jsp.news.news_jsp._jspService(news_jsp.java:361) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at tools.EncodingFilter.doFilter(EncodingFilter.java:55) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:595) 报错完之后数据库的连接才被关闭,然后连接数目一直增加,当再次超过200个时就又报上面的错误,这样情况重复出现,当Tomcat运行两天左右之后,Tomcat就不能服务,网站就打不开了,请高手指点,怎么让Tomcat自动关闭连接池的连接! |