[英]C3P0 settings is ambiguous
我在具有多個服務器的分布式系統上工作,這些服務器與前端MySQL數據庫一起工作,並在不同的查詢中復制數據庫。 幾台服務器使用最多1000個連接的化合物(困難時期為700-800、900)。
我經常遇到MySQL關閉連接的問題,並看到已經很無聊的異常:
The last packet sent successfully to the server was 65,179,696 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.
MySQL的wait_timeout設置是默認設置,等於28800(8小時)
我使用與Hibernate配對的C3P0來服務與MySQL的連接,並在所有hibernate-custom * .xml中的所有服務器上具有下一個C3P0設置:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
<property name="hibernate.connection.url">jdbc:mysql://xxx.xxx.xxx.xxx:3306/ibaserver?autoReconnect=true&useUnicode=true&characterEncoding=cp1251&zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">********</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">50</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.idle_test_period">59</property>
<property name="hibernate.c3p0.acquire_increment">3</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
有人可以回答我在做什么嗎? 為什么定期斷開連接
從池中借用驗證查詢可避免MySQL關閉您的連接異常。
更新
您定義的驗證查詢必須要有一些額外的配置才能運行,這些配置就足夠了:hibernate.c3p0.validate = true hibernate.c3p0.testConnectionOnCheckout = true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.