Java_web:hibernate+mysql超時

mysql若是鏈接閒置8小時 (8小時內沒有進行數據庫操做), mysql就會自動斷開鏈接。mysql

解決辦法:sql

1,connection url中加參數: autoReconnect=trueshell

jdbc.url=jdbc:mysql://ipaddress:3306/database?autoReconnect=true&autoReconnectForPools=true數據庫


2,用hibernate的話, 加以下屬性:tomcat

<?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.session

相關文章
相關標籤/搜索