Tomcat6 - 连接已经关闭

时间:2014-09-10 20:00:57

标签: tomcat6 connection-pooling

几天后,我看到错误' Connection已经关闭'在生产环境中:

以下是数据源配置:

<Resource defaultAutoCommit="true" defaultReadOnly="false"
        driverClassName="oracle.jdbc.OracleDriver"
        factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
        fairQueue="false" initialSize="10"
        jdbcInterceptors="ConnectionState" jmxEnabled="true"
        logAbandoned="true" maxActive="100" maxIdle="50"
        maxWait="30000" minEvictableIdleTimeMillis="5000"
        minIdle="10" name="jdbc/OracleApps" password="APPS"
        removeAbandoned="false" removeAbandonedTimeout="60"
        testOnBorrow="true" testOnReturn="false"
        suspectTimeout="60"
        testWhileIdle="true" timeBetweenEvictionRunsMillis="5000"
        type="javax.sql.DataSource"
        url="jdbcurl"
        useEquals="false" username="APPS" validationInterval="30000" validationQuery="SELECT 2+2 FROM DUAL"/>

我已经通过各种方式尝试了配置,但它仍然会引发相同的错误。任何想法都表示赞赏:

java.sql.SQLException: Connection has already been closed.
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:118)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:94)
at org.apache.tomcat.jdbc.pool.interceptor.ConnectionState.invoke(ConnectionState.java:140)
at $Proxy0.createStatement(Unknown Source)
at cx.PooledDataConnection.open(Unknown Source)
at cx.crm.opportunity.OpportunityHome.getOpportunity(Unknown Source)
at cx.crm.opportunity.OpportunityHome.getOpportunityByPrimaryKey(Unknown Source)
at org.apache.jsp.jsp.WOW.convertquote_jsp._jspService(convertquote_jsp.java:559)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at cx.filter.OrginalURLFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at cx.AppblockerFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:446)
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:372)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:409)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

1 个答案:

答案 0 :(得分:0)

在我的情况下,它发生在池中存在许多打开的连接时,在某些方法中我称为con.close()而不仅仅是。 同样在我的最后,我有以下代码。

    finally {
        try {
              if (con != null) {
                 con.close();
               }
        } catch (SQLException e) {}
    }

这并不能保证连接尚未关闭。

我的tomcat-jdbc.jar版本也很旧了。我将它替换为版本7.0.55最新版本的JDK 1.6版本,即使调用close方法也可以正常工作。