0

每次我的日志文件中都会出现错误:

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 
** BEGIN NESTED EXCEPTION ** 
java.net.SocketException
MESSAGE: Socket closed
STACKTRACE:
java.net.SocketException: Socket closed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
    at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
    at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1994)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2411)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3250)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3179)
    at com.mysql.jdbc.Statement.executeQuery(Statement.java:1207)
    at com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:35)

当应用程序在 MySQL 数据库中执行特定查询时,它总是发生在代码的同一点。

查询是这样的:

SELECT M.*, O.id 
FROM order_message M 
INNER JOIN orders O ON M.order_id = O.id 
WHERE O.seller_id = 14224 AND M.sender_user_id <> 14224 
ORDER BY M.creation_date DESC 
LIMIT 5

我注意到(通过解释这个查询)它总是使用临时/文件排序来执行。所有索引均已正确创建,我认为这些无法改善这一点,但我怀疑查询性能或资源利用率导致异常错误。

我正在使用亚马逊 RDS

4

1 回答 1

0

问题是我的连接池的配置方式是任何花费超过 10 秒的数据库连接都会被连接池 (c3p0) 丢弃。我正在使用 unreturnedConnectionTimeout 参数。

c3p0 文档页面不鼓励使用此参数。理想情况下,所有连接都应该正确关闭(并因此返回到池中)

http://www.mchange.com/projects/c3p0/#unreturnedConnectionTimeout

我已将参数增加到 60 秒,问题得到解决。

于 2013-10-08T18:12:38.820 回答