Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
tProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) ... 23多 原因:java.net.SocketException:管道断裂 位于java.net.SocketOutputStream.socketWrite0(本机方法) 位于java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) 位于java.net.SocketOutputStream.write(SocketOutputStream.java:153) 位于java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) 位于java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) 位于com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3832) ... 33多_Mysql_Hibernate_C3p0_Keep Alive_Broken Pipe - Fatal编程技术网

tProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) ... 23多 原因:java.net.SocketException:管道断裂 位于java.net.SocketOutputStream.socketWrite0(本机方法) 位于java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) 位于java.net.SocketOutputStream.write(SocketOutputStream.java:153) 位于java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) 位于java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) 位于com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3832) ... 33多

tProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) ... 23多 原因:java.net.SocketException:管道断裂 位于java.net.SocketOutputStream.socketWrite0(本机方法) 位于java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) 位于java.net.SocketOutputStream.write(SocketOutputStream.java:153) 位于java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) 位于java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) 位于com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3832) ... 33多,mysql,hibernate,c3p0,keep-alive,broken-pipe,Mysql,Hibernate,C3p0,Keep Alive,Broken Pipe,根据我在互联网上的发现,我尝试了以下方法: 将autoReconnect=true添加到连接URL(请注意,在尝试使用连接后,连接仍然断开,因此似乎没有发生重新连接) 将testConnectionOnCheckout和testConnectionOnCheckin添加到c3p0配置中 将空闲测试周期和preferredTestQuery添加到c3p0配置中 似乎什么都不管用。有人知道是什么导致了这个问题吗?所以,有一些零散的想法: 您的preferredTestQuery中有错误。它应该是

根据我在互联网上的发现,我尝试了以下方法:

  • 将autoReconnect=true添加到连接URL(请注意,在尝试使用连接后,连接仍然断开,因此似乎没有发生重新连接)
  • 将testConnectionOnCheckout和testConnectionOnCheckin添加到c3p0配置中
  • 将空闲测试周期和preferredTestQuery添加到c3p0配置中

似乎什么都不管用。有人知道是什么导致了这个问题吗?

所以,有一些零散的想法:

您的
preferredTestQuery
中有错误。它应该是“选择1”,而不是“选择1;”。我认为如果这是一个问题,你会看到关于它的异常(并且签出都会失败),但值得尝试修复它

[您使用的是哪个版本的c3p0?如果您想过上危险的生活,并且正在使用最新的MySQL驱动程序,请尝试使用最新的预发行版,当前为c3p0-0.9.5-pre8,并且根本不设置
preferredTestQuery
。最新版本支持JDBC4 Connection.isValid()进行测试。]

另一种可能是您的应用程序偶尔会将连接保持打开(签出)很长时间。这不会造成连接泄漏,因为最终应用程序会尝试针对连接执行语句。但如果您的应用程序执行此操作,您将看到所看到的内容,因为c3p0不会在客户端使用连接时测试连接,因此它们将能够空闲。(我不知道为什么autoReconnect没有帮助,除非您可能处于事务处理中期,autoReconnect对此不起作用?)如果您想测试此场景,您可以使用(可选)强制关闭过长的签出异常,并尝试诊断问题

如果您只是希望问题消失(并且不太关心理解它),您也可以尝试设置c3p0和/或。如果将这些设置为较大的值,则这些设置不会对性能产生显著影响。(可能是7200秒,即两个小时,但任何超过1800秒的都可以。)这些设置(尤其是maxConnectionAge)非常简单,除非根据上面的说明,麻烦的连接保持打开并签出池很长时间。[将关闭()从客户端下签出的连接的唯一c3p0设置是
unreturnedConnectionTimeout
]


祝你好运

非常感谢你的回答!问题可能确实是我将会话保持长时间打开(我不知道这是否意味着连接也保持打开)。我使用的是c3p0版本0.9.1。我刚刚在配置中添加了unreturnedConnectionTimeout(值=10800)、debugUnreturnedConnectionStackTraces、maxConnectionAge和maxIdleTime(两个值都=7200),并修复了testQuery。由于这个问题只会在大约8小时后发生(MySQL连接超时),所以我必须等到明天,看看这是否解决了这个问题。我会让你知道的!看来问题解决了,非常感谢!在实现上述更改后,仍然存在一个问题,即所讨论的线程试图使用一个已经关闭的连接(没有断开的管道,只有一个关闭的连接)。由于我手动管理hibernate会话(我决定何时打开和关闭会话,而不是从配置中的thread context类中获益),因此我必须在自定义sessionmanager类中实现超时,该类在一定空闲时间后优雅地关闭会话。从那以后,一切都很顺利!
    <hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/**********?autoReconnect=true</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
        <property name="hibernate.connection.username">********</property>
        <property name="hibernate.connection.password">********</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.globally_quoted_identifiers">true</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
        <property name="hibernate.connection.autocommit">false</property>
        <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">25</property>
        <property name="hibernate.c3p0.timeout">300</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.idle_test_period">60</property>
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.acquireRetryAttempts">5</property>
        <property name="hibernate.c3p0.acquireRetryDelay">250</property>
        <property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
        <property name="hibernate.c3p0.validate">true</property>
        <property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
        <property name="hibernate.c3p0.testConnectionOnCheckin">true</property>
    </session-factory>
</hibernate-configuration>
The last packet successfully received from the server was 56,974,967 milliseconds ago. The last packet sent successfully to the server was 56,974,967 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. org.hibernate.exception.JDBCConnectionException: The last packet successfully received from the server was 56,974,967 milliseconds ago. The last packet sent successfully to the server was 56,974,967 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. Apr 08, 2014 10:57:13 AM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@f79fb235 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@4e20d034 [ acquireIncrement -> 1, acquireRetryAttempts -> 5, acquireRetryDelay -> 250, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> ph9ube91hyyxjw1mgbhpo|709689fb, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 25, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@a1ca3a3 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> ph9ube91hyyxjw1mgbhpo|24bbab7, jdbcUrl -> jdbc:mysql://localhost:3306/********?autoReconnect=true, properties -> {user=******, password=******, autocommit=false} ], preferredTestQuery -> select 1;, propertyCycle -> 0, testConnectionOnCheckin -> true, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> ph9ube91hyyxjw1mgbhpo|fedb05d, numHelperThreads -> 3 ] Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 56,974,967 milliseconds ago. The last packet sent successfully to the server was 56,974,967 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 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:525) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3851) 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:2683) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2310) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) ... 23 more Caused by: java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) 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) ... 33 more