通信链路错误 - MySQL超时

时间:2014-09-25 18:21:23

标签: java mysql

我在MySQL数据库连接打开大约5分钟后收到通信链接错误(MySQL连接器),我认为这可能是因为如果连接在5分钟内TCP连接上没有活动。

我试图更改超时:

 int val = new BigDecimal("7.2e+6").intValue(); // Set default timeout to 2 hours
 con.setNetworkTimeout(Executors.newFixedThreadPool(1), val);

不会抛出任何错误,所以我猜它接受了2小时的时间,但我仍然收到通讯链接错误:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 379,400 milliseconds ago.  The last packet sent successfully to the server was 379,752 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1129)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3988)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2598)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2834)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
at createArticle.ArticleSelectConnect.UploadArticleProcess(ArticleSelectConnect.java:61)
at createArticle.CreateArticleController.UploadArticle(CreateArticleController.java:208)
at createArticle.CreateArticleController.SubmitArticle(CreateArticleController.java:64)
at createArticle.CreateArticleToolbar$1.run(CreateArticleToolbar.java:169)

Caused by: java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:122)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3968)
... 9 more

有谁知道我能做什么,所以我可以在后台打开连接,暂时不做任何事情? - 如果我只是立即发送一些数据(大约5分钟内),它工作正常。

0 个答案:

没有答案