Official Document: http://www.mchange.com/projects/c3p0/index.html<c3p0-config><default-config><!--c3p0 The number of connections that are fetched at the same time when the connection in the connection pool is exhausted. Default:3--><property name= "acquireincrement" >3</property><!--defines the number of repeated attempts to obtain a new connection from the database after a failure. default:30--><property name= "acquireretryattempts" >30</property><!--Two-connection interval, in milliseconds. default:1000--><property name= "Acquireretrydelay" >1000</property><!--the connection is closed by default, all uncommitted actions are rolled back. Default:false--><property name= "Autocommitonclose" >false</property><!--C3P0 will build an empty table named Test and test it with its own query statement. If this parameter is defined, then the attribute preferredtestquery will be ignored. You cannot do anything on this test sheet, it will be used only for C3P0 testing. Default:NULL--><property name= "automatictesttable" >Test</property><!--getting a connection failure will cause any thread that waits for the connection pool to get the connection to throw an exception. However, the data source is still valid and continues to try to get the connection the next time you call Getconnection (). If set to True, the data source will declare broken and permanently shut down after attempting to acquire a connection failure. Default:false--><property name= "Breakafteracquirefailure" >false</property><!--When the connection pool runs out, the client calls getconnection () to wait for a new connection, and after the timeout, the SqlException is thrown and, if set to 0, waits indefinitely. Unit milliseconds. Default:0--><property name= "checkouttimeout" >100</property><!--test the connection by implementing a Connectiontester or Queryconnectiontester class. The class name needs to be set to the full path. Default:com.mchange.v2.c3p0.impl.DefaultConnectionTester--><property name= "Connectiontesterclassname" ></property><!--specifies the path of the C3P0 libraries, which is not required if (as is often the case), and defaults to NULL if it is available locally:NULL--><property name= "Factoryclasslocation" >NULL</property><!--strongly disrecommended. Setting ThisTotruemay leads to subtle and bizarre bugs. (original document) an attribute that the author strongly recommends not to use--><property name= "Forceignoreunresolvedtransactions" >false</property><!--Check for idle connections in all connection pools every 60 seconds. default:0--><property name= "Idleconnectiontestperiod" >60</property><!--get three connections when initializing, The value should be between Minpoolsize and Maxpoolsize. Default:3--><property name= "initialpoolsize" >3</property><!--maximum idle time, unused in 60 seconds, the connection is discarded. If 0, it will never be discarded. default:0--><property name= "MaxIdleTime" >60</property><!--the maximum number of connections that are kept in the connection pool. Default:15--><property name= "maxpoolsize" >15</property><!--the standard parameters of JDBC to control the number of preparedstatements loaded within the data source. However, because the pre-cached statements belong to a single connection instead of the entire connection pool. So setting this parameter takes into account a variety of factors. If both maxstatements and maxstatementsperconnection are 0, the cache is closed. Default:0--><property name= "maxstatements" >100</property><!-- Maxstatementsperconnection defines the maximum number of cache statements that a single connection in a connection pool has. default:0--><property name= "maxstatementsperconnection" ></property><!--c3p0 are asynchronous operations, and slow JDBC operations are done by helping the process. Extending these operations can effectively improve performance by implementing multiple operations at the same time through multithreading. Default:3--><property name= "Numhelperthreads" >3</property><!--when the user calls getconnection (), the root user becomes the user to get the connection. Used primarily when connection pooling is connected to a non-c3p0 data source. Default:NULL--><property name= "Overridedefaultuser" >root</property><!--a parameter that corresponds to the Overridedefaultuser parameter. Default:NULL--><property name= "Overridedefaultpassword" >password</property><!--password. Default:NULL--><property name= "Password" ></property><!--defines test statements that are executed by all connection tests. This one significantly improves the test speed in the case of connection testing. Note: The test table must exist at the time of the initial data source. Default:NULL--><property name= "preferredtestquery" >select ID from test where id=1</property><!-- The user waits up to 300 seconds before modifying the system configuration parameters to execute. default:300--><property name= "propertycycle" >300</property><!--Please use it only when you need it because of high performance consumption. If set to true then the validity of each connection submission is officer. We recommend using methods such as Idleconnectiontestperiod or automatictesttable to improve the performance of your connectivity tests. Default:false--><property name= "Testconnectiononcheckout" >false</property><!--If set to true then officer the validity of the connection while the connection is made. Default:false--><property name= "Testconnectiononcheckin" >true</property><!--user name. Default:NULL--><property name= "User" >root</property><!--The earlier version of C3P0 uses a dynamic reflection proxy for the JDBC interface. This parameter allows the user to revert to the dynamic reflection agent to resolve an unstable failure in the case of a wide range of uses in earlier versions. The newest non-reflection agents are faster and have started to be widely used, so this parameter may not be useful. The original dynamic reflection is now supported at the same time as the new non-reflection agent, but a possible future version may not support the dynamic reflection proxy. 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>ext: http://www.wujianrong.com/archives/2007/08/c3p0.htmlsolve MySQL 8-hour problem The most recent project in Hibernate uses C3P0 's connection pool, the database is MySQL. There is no problem with development testing, and an exception occurs for each long idle time in the run: Java code org.hibernate.exception.JDBCConnectionException:could not execute Queryat Org.hibernate.exception.SQLStateConverter.convert (Sqlstateconverter.java:74) at Org.hibernate.exception.JDBCExceptionHelper.convert (Jdbcexceptionhelper.java:43)....... caused By:com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException:No operations allowed after connection Closed. Connection was implicitly closed due to underlying exception/Error:* * BEGIN NESTED EXCEPTION * *com.mysql.jdbc.CommunicationsExceptionMESSAGE:Communications link failure due to underlying exception:* * BEGIN NESTED EXCEPTION * *Java.net.SocketExceptionMESSAGE:Broken PipeSTACKTRACE:java.net.SocketException:Broken Pipeat Java.net.SocketOutputStream.socketWrite0 (Native Method) ...* * END NESTED EXCEPTION * *viewed the MySQL documentation, as well as the connector/J's documentation and online instructions found that the reason for this exception is that the default "Wait_timeout" of the MySQL server is 8 hours, which means that a connection is idle for more than 8 hours and MySQL will automatically disconnect the connection. This is the problem, in the C3P0 pools connections if idle for more than 8 hours, MySQL will disconnect it, and c3p0 do not know that the connection has failed, if there is a client request connection, C3P0 the failure of the connection to the client, will cause the above exception. There are 3 ways to solve this problem: increase the time of wait_timeout. Reduce the lifetime of connection in connection pools. Test the effectiveness of connection in connection pools. Of course, the best way is to combine the above 3 methods, the following DBCP and C3P0 to do a separate description, assuming wait_timeout for the default 8 hours DBCP Add the following configuration information://set to ' SELECT 1 'Validationquery = "Select 1"//set to ' true 'Testwhileidle = "true"//some positive integerTimebetweenevictionrunsmillis = 3600000//set to something smaller than ' wait_timeout 'Minevictableidletimemillis = 18000000//If you don ' t mind a hits for every getconnection (), set to "true"Testonborrow = "true"C3P0 Add the following configuration information://whether the test is valid when getting connnectionTestconnectiononcheckin =true//table name of the automated testautomatictesttable=c3p0testtable//set to something much less than wait_timeout, prevents connections from going staleIdleconnectiontestperiod = 18000//set to something slightly less than wait_timeout, preventing ' stale ' connections from being handed outMaxIdleTime = 25000//If you can take the performance ' hits ', set to ' true 'Testconnectiononcheckout =trueMore configuration information you can view the C3P0 documentation, Connector/J documentation, as well as DBCP's documentation. Ext: http://www.javaeye.com/article/38506my own configuration: Jdbc.driverclass=COM.MYSQL.JDBC.DRIVERJDBC.JDBCURL= Jdbc:mysql://localhost:3306/testJdbc.user =Rootjdbc.password= 12345jdbc.minipoolsize= 1jdbc.maxpoolsize= 20jdbc.initialpoolsize= 1Jdbc.maxidletime= 25000jdbc.acquireincrement= 1jdbc.acquireretryattempts= 30Jdbc.acquireretrydelay= 1000Jdbc.testconnectiononcheckin=truejdbc.automatictesttable=C3p0testtablejdbc.idleconnectiontestperiod= 18000Jdbc.checkouttimeout=3000<bean id= "DataSource"class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" > <property name= "driverclass" value= "${ Jdbc.driverclass} "/> <property name=" Jdbcurl "value=" ${jdbc.jdbcurl} "/> <property name=" user "value=" ${j Dbc.user} "/> <property name=" password "value=" ${jdbc.password} "/> <property name=" minpoolsize "value=" ${ Jdbc.minipoolsize} "/> <property name=" maxpoolsize "value=" ${jdbc.maxpoolsize} "/> <property name=" Initia Lpoolsize "value=" ${jdbc.initialpoolsize} "/> <property name=" maxidletime "value=" ${jdbc.maxIdleTime} "/> <property name= "acquireincrement" value= "${jdbc.acquireincrement}"/> <property name= "acquireRetryAttempts "Value=" ${jdbc.acquireretryattempts} "/> <property name=" Acquireretrydelay "value=" ${jdbc.acquireRetryDelay} "/> <property name=" Testconnectiononcheckin "value=" ${jdbc.testconnectiononcheckin} "/> <property name=" Automatictesttable "Value=" ${jdbc.automatictesttable} "/> <property name=" idleconnectiontestperiod "value=" ${jdbc.idleconnectiontestperiod} "/> <property Name= "Checkouttimeout" value= "${jdbc.checkouttimeout}"/></bean>
160905, c3p0 detailed configuration