我正在使用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
<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"/>
你们中是否有人对此话题有任何经验并可以帮助我?
答案 0 :(得分: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" />