【问题标题】:Connection pool issue: Connection has already been closed连接池问题:连接已关闭
【发布时间】:2014-07-25 09:11:00
【问题描述】:

我正在使用 Grails 2.4.2、Tomcat 7 和 MySQL 5.6.17,但连接池有问题。一段时间后,我的应用程序随机报告以下错误。

2014-07-24 08:24:35,012 [http-bio-127.0.0.1-50000-exec-9] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Connection has already been closed.

2014-07-25 10:55:12,018 [http-bio-127.0.0.1-50000-exec-6] ERROR org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver - SQLException occurred when processing request: [GET] /controller/index
Connection has already been closed.. Stacktrace follows:
java.sql.SQLException: Connection has already been closed.
        at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:189)
        at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
        at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
        at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
        at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

这里是$TOMCAT_HOME/conf/context.xml中定义的JNDI数据源资源

<Resource name="jdbc/xxx" auth="Container" type="javax.sql.DataSource"
                username="user" password="password"
                driverClassName="com.mysql.jdbc.Driver"
                factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                url="jdbc:mysql://localhost:3306/db?generateSimpleParameterMetadata=true"
                validationQuery="SELECT 1"
                validationInterval="30000"
                initialSize="5"
                maxActive="50"
                minIdle="5"
                maxIdle="30"
                maxWait="10000"
                timeBetweenEvictionRunsMillis="5000"
                minEvictableIdleTimeMillis="55000"
                testOnBorrow="true"
                removeAbandoned="true"
                removeAbandonedTimeout="55"/>

你们中是否有人在这个主题上有任何经验并且可以在这方面帮助我?

【问题讨论】:

  • 我也在用 testWhileIdle="true"

标签: mysql grails tomcat7


【解决方案1】:

切换到 C3P0 连接池完成了这项工作。

<Resource auth="Container"
                  description="DB Connection"
                  driverClass="com.mysql.jdbc.Driver"
                  maxPoolSize="10"
                  minPoolSize="2"
                  acquireIncrement="1"
                  name="jdbc/xxx"
                  user="user"
                  password="password"
                  factory="org.apache.naming.factory.BeanFactory"
                  type="com.mchange.v2.c3p0.ComboPooledDataSource"
                  jdbcUrl="jdbc:mysql://localhost:3306/db?generateSimpleParameterMetadata=true" />

【讨论】:

    猜你喜欢
    • 2014-09-19
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多