现在项目已经发布到服务器,前一天还没什么问题,但是第二天,在运行,老是报com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 54,522,939 milliseconds ago. The last packet sent successfully to the server was 54,522,940 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.
网上查了一下,大致意思就是说,当你第一次访问运用,c3p0建立了连接,但是Mysql 连接指等待8小时,超过8小时之后,Mysql就关掉了该进程,而c3p0却没有销毁该连接,当你8小时之后再次访问,就拿的是Mysql关闭的那个连接,所以抛出了此次异常,当你再次访问的时候,又恢复了正常
我的配置文件如下
<property name="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>
<!-- 最大连接数 -->
<property name="hibernate.c3p0.max_size">30</property>
<!-- 最小连接数 -->
<property name="hibernate.c3p0.min_size">5</property>
<!-- 最大的PreparedStatement的数量 -->
<property name="hibernate.c3p0.max_statements">50</property>
<!-- 如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat. -->
<!-- 不用hibernate的话, connection url加参数: autoReconnect=true -->
<!-- 用hibernate的话, 加如下属性: -->
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
<!-- 要是还用c3p0连接池: -->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">0</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.validate">true</property>
网上说,可以解决,但是问题依旧,不想改Mysql 的配置文件,那样就不健壮了。请问,怎么解决,跪谢!!!
按照网上说的配好多种配置文件,还是不行。如下其他配置
(1)
<property name="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>
<!-- 最大连接数 -->
<property name="hibernate.c3p0.max_size">30</property>
<!-- 最小连接数 -->
<property name="hibernate.c3p0.min_size">5</property>
<!-- 最大的PreparedStatement的数量 -->
<property name="hibernate.c3p0.max_statements">50</property>
<!-- 如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat. -->
<!-- 不用hibernate的话, connection url加参数: autoReconnect=true -->
<!-- 用hibernate的话, 加如下属性: -->
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
<!-- 要是还用c3p0连接池: -->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">0</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.validate">true</property>
<property name="c3p0.testConnectionOnCheckout">true</property>
<property name="c3p0.testConnectionOnCheckin ">true</property>
<property name="c3p0.automaticTestTable">C3P0TestTable</property>
<property name="c3p0.maxIdleTime">25000</property>
(2)
<!-- 如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat. -->
<!-- 不用hibernate的话, connection url加参数: autoReconnect=true -->
<!-- 用hibernate的话, 加如下属性: -->
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
<!-- 要是还用c3p0连接池: -->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">0</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.validate">true</property>
跪谢。,。。。。。。。。。。。。