Java_Web:hibernate+mysqlタイムアウト
1985 ワード
mysql接続が8時間アイドル(8時間以内にデータベース操作が行われない)の場合、mysqlは自動的に接続を切断します.
解決策:
1,connection urlにパラメータを追加する:autoReconnect=true
jdbc.url=jdbc:mysql://ipaddress:3306/database?autoReconnect=true&autoReconnectForPools=true
2、hibernateを使うと、以下の属性が加算されます.
3、shellスクリプトを書いて、tomcatをタイミング的に再起動します.terrible.
解決策:
1,connection urlにパラメータを追加する:autoReconnect=true
jdbc.url=jdbc:mysql://ipaddress:3306/database?autoReconnect=true&autoReconnectForPools=true
2、hibernateを使うと、以下の属性が加算されます.
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">aaa</property>
<property name="hibernate.connection.password">aaa</property>
<!-- c3p0 -->
<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">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- others -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<mapping resource="com/xinju/hibernate/Event.hbm.xml"/>
</session-factory>
</hibernate-configuration>
3、shellスクリプトを書いて、tomcatをタイミング的に再起動します.terrible.