相关疑难解决方法(0)

在MySQL,Grails 2应用程序更长时间不活动期间保持池连接活动(或将它们计时并获得新的连接)的正确方法

我有一个grails应用程序,有高活动的flurries,但往往是一段时间不活动,可以持续几个小时到一个晚上.我注意到早上的第一个用户得到以下类型的异常,我相信这是由于池中的连接过时而MYSql数据库关闭它们.

我在Googling中发现了有关使用Connector/J连接属性'autoReconnect = true'是否是一个好主意的信息(以及即使连接被恢复,客户端是否仍会获得异常),或者是否设置其他属性将周期性地逐出或刷新空闲连接,测试借用等.Grails使用下面的DBCP.我目前有一个简单的配置,如下所示,我正在寻找一个答案,如何最好地确保在长时间非活动期间有效且未关闭后从池中抓取任何连接.

dataSource {
        pooled = true
        dbCreate = "update"
        url = "jdbc:mysql://my.ip.address:3306/databasename"
        driverClassName = "com.mysql.jdbc.Driver"
        dialect = org.hibernate.dialect.MySQL5InnoDBDialect
        username = "****"
        password = "****"
        properties {
          //what should I add here?
          }
    }
Run Code Online (Sandbox Code Playgroud)

例外

    2012-06-20 08:40:55,150 [http-bio-8443-exec-1] ERROR transaction.JDBCTransaction  - JDBC begin failed
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 64,129,968 milliseconds ago.  The last packet sent successfully to the server was 64,129,968 milliseconds ago. is longer than the server configured value of 'wait_timeout'. …
Run Code Online (Sandbox Code Playgroud)

mysql grails connection-pooling connector-j

37
推荐指数
2
解决办法
7万
查看次数

java.sql.SQLException:已经关闭

我们在tomcat上运行了一个带有MySQL后端的webapp.一切都很好,然后突然我们开始得到这个例外java.sql.SQLException: Already closed.

整个堆栈跟踪是:

DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] Fetching JDBC Connection from DataSource
DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] Returning JDBC Connection to DataSource
DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] Could not close JDBC Connection    
java.sql.SQLException: Already closed.
    at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:114)
    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)
    at org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:333)
    at org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection(DataSourceUtils.java:294)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:405)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:428)
    at com.nokia.analytics.aws.aggregate.service.importer.DBInsert.truncateTable(DBInsert.java:135)
    at com.blah.analytics.aggregate.service.importer.AggregateCollector.pullAndInsert(AggregateCollector.java:85)
    at com.blah.analytics.aggregate.service.importer.AggregateCollector.call(AggregateCollector.java:96)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:679)
Run Code Online (Sandbox Code Playgroud)

我们正在使用org.apache.commons.dbcp.BasicDataSource我们的数据源.我搜索了不少但无济于事.它不会总是发生,因此很难再现.这似乎是db连接池的问题.有人建议将此参数设置为否定.目前我们没有更改这些参数(都具有默认值).

我们应该采取什么方法来避免它?

编辑:

相关代码在(DBInsert.java)中

133: String sql = "DELETE FROM "+tableName;

134: logger.debug(sql);

135: this.jdbcTemplate.execute(sql);

(133-135是行号,在例外中指定)

我的数据源配置:

<bean id="bisToolDataSource" …
Run Code Online (Sandbox Code Playgroud)

mysql spring tomcat

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

mysql ×2

connection-pooling ×1

connector-j ×1

grails ×1

spring ×1

tomcat ×1