c 3 p 0接続池の詳細な配置
公式文書:
http://www.mchange.com/projects/c3p0/index.html
回転:
http://www.wujianrong.com/archives/2007/08/c3p0.html
MYSQL 8時間の問題を解決します。
一番近い項目はHibernateでC 3 P 0の接続池を使っています。データベースはMysqlです。開発テストは問題ありません。運転中は長い間の空き時間に異常が発生します。
javaコード
org.hibernate.exception.JDBCConnection Exception:could not execute queryat org.hibernate.exception.SQLStateContverter.co nvert(SQLStateConter.java:74) at org.hibernate.exception.JDBCException Helper.co nvert(JDBCException Helper.java:43)・・ Caused by:comp.mysql.jdbc.exceptions.MySLNonTransientConnection Exception:No operation allowed after connection closed.connection was implicitly closed due to undering exception/error:4591678・*BEGIN NESTEP EXCEPTION* comp.mysql.jdbc.communications Exception MESSAGE:Communications link failure due to undering exception:*BEGIN NESTER EXCEPTION*java.net.SocketExceptionMESSAGE:Broken pipe STACKTRACE: java.net.SocketException:Broken pipe at java.net.SocketOutputStream.socketWrite 0(Native Method)・・ *END NESTER EXCEPTION*Mysqlの文書とConnector/Jの文書とオンライン説明を見たら、この異常な原因は:
Mysqlサーバのデフォルトの「wait uutimeout」は8時間、つまりconnectionの空き時間が8時間を超えると、Mysqlは自動的にこのコンサートを切断します。これは問題の所在です。C 3 P 0 poolsでのconnectionsの空き時間が8時間を超えると、Mysqlが切断されます。C 3 P 0はこのconnectionが失効したことを知らないです。もしCientがconnectionを要求したら、C 3 P 0はこの失効したConnectionをCientに提供し、上面の異常を引き起こします。
解決の方法は3つあります。wait_を増やすタイムアウトの時間 Connection poolsでのconnectionのlifetimeを減らす。 Connection poolsでのconnectionの有効性をテストします。 もちろん、上記3つの方法を併用しながら、DBCPとC 3 P 0についてそれぞれ説明します。timeoutはデフォルトの8時間です。
DBCPには以下の設定情報が追加されます。
//set to'SELECT 1'validationQuery= 「SELECT 1」 //set to'true'testWhileIdle= 「true」 //some positive integertimeBetweenEnitionRuns Millis= 360000 //set to something smaler than'wait_timeout'minEverictable IdleTimeMillis= 1800000 //if you don't mind a hit for evy get Connection()、set to「true」test OnBorrow= 「true」 C 3 P 0は、以下の構成情報を追加します。
//connnectionを取得する時、有効かどうかをテストするtestConnection OnCheckin=true //自動試験のテーブル名 atomatic TestTable=C 3 P 0 TestTable //set to something much less than wait_timeout、prevents connections from going staleidleConnection TestPeriod= 18000 //set to something sless than wait_timeout、preventing'stale'connections from being handoutmaxIdleTime= 25000 //if you can take the performance'hit、set to「true」testConnection OnCheckout= true
http://www.mchange.com/projects/c3p0/index.html
<c3p0-config>
<default-config>
<!-- c3p0 。Default: 3 -->
<property name="acquireIncrement">3</property>
<!-- 。Default: 30 -->
<property name="acquireRetryAttempts">30</property>
<!-- , 。Default: 1000 -->
<property name="acquireRetryDelay">1000</property>
<!-- 。Default: false -->
<property name="autoCommitOnClose">false</property>
<!--c3p0 Test , 。 preferredTestQuery 。 Test , c3p0 。Default: null-->
<property name="automaticTestTable">Test</property>
<!-- 。 , getConnection() 。 true, 。Default: false-->
<property name="breakAfterAcquireFailure">false</property>
<!-- getConnection() , SQLException, 0 。 。Default: 0 -->
<property name="checkoutTimeout">100</property>
<!-- ConnectionTester QueryConnectionTester 。 。Default: com.mchange.v2.c3p0.impl.DefaultConnectionTester-->
<property name="connectionTesterClassName"></property>
<!-- c3p0 libraries , ( ) , null . Default: null-->
<property name="factoryClassLocation">null</property>
<!--Strongly disrecommended. Setting this to true may lead to subtle and bizarre bugs.( ) -->
<property name="forceIgnoreUnresolvedTransactions">false</property>
<!-- 60 。Default: 0 -->
<property name="idleConnectionTestPeriod">60</property>
<!-- , minPoolSize maxPoolSize 。Default: 3 -->
<property name="initialPoolSize">3</property>
<!-- ,60 。 0 。Default: 0 -->
<property name="maxIdleTime">60</property>
<!-- 。Default: 15 -->
<property name="maxPoolSize">15</property>
<!--JDBC , PreparedStatements 。 statements connection 。 。 maxStatements maxStatementsPerConnection 0, 。Default: 0-->
<property name="maxStatements">100</property>
<!--maxStatementsPerConnection statements 。Default: 0 -->
<property name="maxStatementsPerConnection"></property>
<!--c3p0 , JDBC 。 。Default: 3-->
<property name="numHelperThreads">3</property>
<!-- getConnection() root 。 c3p0 。Default: null-->
<property name="overrideDefaultUser">root</property>
<!-- overrideDefaultUser 。Default: null-->
<property name="overrideDefaultPassword">password</property>
<!-- 。Default: null-->
<property name="password"></property>
<!-- 。 。 : 。Default: null-->
<property name="preferredTestQuery">select id from test where id=1</property>
<!-- 300 。Default: 300 -->
<property name="propertyCycle">300</property>
<!-- 。 true connection 。 idleConnectionTestPeriod automaticTestTable 。Default: false -->
<property name="testConnectionOnCheckout">false</property>
<!-- true 。Default: false -->
<property name="testConnectionOnCheckin">true</property>
<!-- 。Default: null-->
<property name="user">root</property>
<!-- c3p0 JDBC 。 。 , 。 , 。Default: false-->
<property name="usesTraditionalReflectiveProxies">false</property>
<property name="automaticTestTable">con_test</property>
<property name="checkoutTimeout">30000</property>
<property name="idleConnectionTestPeriod">30</property>
<property name="initialPoolSize">10</property>
<property name="maxIdleTime">30</property>
<property name="maxPoolSize">25</property>
<property name="minPoolSize">10</property>
<property name="maxStatements">0</property>
<user-overrides user="swaldman">
</user-overrides>
</default-config>
<named-config name="dumbTestConfig">
<property name="maxStatements">200</property>
<user-overrides user="poop">
<property name="maxStatements">300</property>
</user-overrides>
</named-config>
</c3p0-config>
回転:
http://www.wujianrong.com/archives/2007/08/c3p0.html
MYSQL 8時間の問題を解決します。
一番近い項目はHibernateでC 3 P 0の接続池を使っています。データベースはMysqlです。開発テストは問題ありません。運転中は長い間の空き時間に異常が発生します。
javaコード
org.hibernate.exception.JDBCConnection Exception:could not execute query
Mysqlサーバのデフォルトの「wait uutimeout」は8時間、つまりconnectionの空き時間が8時間を超えると、Mysqlは自動的にこのコンサートを切断します。これは問題の所在です。C 3 P 0 poolsでのconnectionsの空き時間が8時間を超えると、Mysqlが切断されます。C 3 P 0はこのconnectionが失効したことを知らないです。もしCientがconnectionを要求したら、C 3 P 0はこの失効したConnectionをCientに提供し、上面の異常を引き起こします。
解決の方法は3つあります。
DBCPには以下の設定情報が追加されます。
//set to'SELECT 1'
//connnectionを取得する時、有効かどうかをテストする