Java 冬眠+;c3p0连接重新打开

Java 冬眠+;c3p0连接重新打开,java,mysql,spring,hibernate,c3p0,Java,Mysql,Spring,Hibernate,C3p0,我在使用hinermate连接配置c3p0连接池时遇到一些问题 我已经将MySQL服务器的等待时间设置为180秒 我的hibernate属性文件中还设置了以下参数: properties.put("hibernate.connection.driver_class", JDBC_DRIVER); properties.put("hibernate.connection.url", JDBC_URL); properties.put("hibernate.connection.username",

我在使用hinermate连接配置c3p0连接池时遇到一些问题

我已经将MySQL服务器的等待时间设置为180秒

我的hibernate属性文件中还设置了以下参数:

properties.put("hibernate.connection.driver_class", JDBC_DRIVER);
properties.put("hibernate.connection.url", JDBC_URL);
properties.put("hibernate.connection.username", JDBC_USER);
properties.put("hibernate.connection.password", JDBC_PASSWORD);
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
properties.put("hibernate.show_sql", false);
properties.put("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");
properties.put("hibernate.c3p0.min_size", 1);
properties.put("hibernate.c3p0.max_size", 10);
properties.put("hibernate.c3p0.max_statements", 8 );
我已经创建了一个c3p0属性文件,并将其添加到我的资源文件夹中。该文件的内容如下:

c3p0.testConnectionOnCheckout=true
仅此而已。当我读到一些属性只能在这个文件中设置时,这就是这个特定配置文件中剩下的全部内容。加载应用程序c3p0初始化后,我会打印以下日志消息:

信息:正在初始化c3p0池。。。 com.mchange.v2.c3p0。PoolBackedDataSource@b014587e [ connectionPoolDataSource-> com.mchange.v2.c3p0。WrapperConnectionPoolDataSource@5e2902db [ acquireIncrement->3,收单机构尝试->30,收单机构播放 ->1000,自动提交关闭->假,自动测试表->空,breakAfterAcquireFailure->假,签出超时->0, connectionCustomizerClassName->null,ConnectionTestClassName-> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces->false,factoryClassLocation-> null,ForceIgnoreUnsolvedTransactions->false,identityToken-> 1hge17r9d37v2wm1n57lrr | ba81af,空闲连接测试周期->0, initialPoolSize->1,maxAdministrativeTaskTime->0,maxConnectionAge ->0,maxIdleTime->0,maxIdleTimeExcessConnections->0,maxPoolSize->10,maxStatements->8,maxStatementsPerConnection->0,minPoolSize->1,nestedDataSource-> com.mchange.v2.c3p0。DriverManagerDataSource@d4187fd7[说明-> null,driverClass->null,factoryClassLocation->null,identityToken ->1hge17r9d37v2wm1n57lrr | 1434751,jdbcUrl->jdbc:mysql://localhost:3306/whatever?characterEncoding=UTF-8、财产 ->{user=*******,password=******}],preferredTestQuery->null,propertyCycle->0,statementCacheNumDeferredCloseThreads->0, testConnectionOnCheckin->false,testConnectionOnCheckout->true, 未返回的连接超时->0,使用传统反射代理-> false;userOverrides:{}],dataSourceName->null, factoryClassLocation->null,identityToken-> 1hge17r9d37v2wm1n57lrr | 2a237a,numHelperThreads->3]

看来一切都准备好了

我开始配置此连接池,因为在获得第一个连接的8小时内,服务器上出现了断管问题。因此,作为一项测试,我在服务器上设置了wait_timeout no,正如我提到的,持续180秒,在我尝试执行数据库调用时遇到问题之后:

原因:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 从服务器成功接收的最后一个数据包是xxx 几毫秒前。成功发送到服务器的最后一个数据包为 xxx毫秒前。比配置的服务器长 “等待超时”的值。你应该考虑过期和/或 在应用程序中使用之前测试连接有效性,增加 服务器为客户端超时配置了值,或使用 连接器/J连接属性“autoReconnect=true”可避免此情况 问题 原因:java.net.SocketException:管道断裂

我正在使用以下相关的maven依赖项:

 <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>5.0.0.Final</version>
    </dependency>

org.hibernate
冬眠核心
5.0.0.1决赛
org.hibernate
hibernate-c3p0
5.0.0.1决赛
设置c3p0以避免管道破裂问题的最简单方法是什么

我已经尝试了preferredTestQuery=select1方法,在数字IDLECONNECTONTESTPERIOD上玩过,但似乎没有任何效果

我可能遗漏了一些非常简单的东西,我可以使用一些指导

谢谢,
彼得

救援文件!:(读取
idleConnectionTestPeriod
)hi周围的位。听起来好像你正在使用的连接不是从你正在查看的数据源派生出来的,或者你的应用程序中的某些东西持有对连接的引用,而不是根据需要将它们签出。您是否可以发布所看到的异常的完整堆栈跟踪,而不仅仅是消息?