0

我在 tomcat 7 中部署了一个 grails 应用程序。数据库连接在正常时间工作正常,但在晚上连接关闭。第二天我必须重新启动tomcat才能使其工作。

这是我在配置文件中的连接字符串。

production {
        dataSource {
            dbCreate = "update"
            pooled = true
                        logSql = true
                        driverClassName =  "com.mysql.jdbc.Driver"
                        dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
                        url =
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }

错误日志:

Broken pipe. Stacktrace follows:
java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3832)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2471)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2728)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2678)
        at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1612)

我也在日志文件中看到了这条消息。

appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.

如何解决连接超时问题。

4

1 回答 1

2

您必须添加autoReconnect=true到连接 url,这将有助于解决此类连接问题。

喜欢:

production {
  dataSource {
    ...
    url = 'jdbc:mysql://localhost/dbname?autoReconnect=true'
    ...
  }
}
于 2013-05-18T13:00:14.720 回答