c3p0 is an open source JDBC Connection pool that is published in the Lib directory with Hibernate, including the connection and statement pools that implement the JDBC3 and JDBC2 extension specification descriptions datasources Object.BONECP is an open source, fast JDBC connection pool. BONECP is very small, only more than 40 K (runtime needs log4j and Google Collections support, which add up is not small), compared to
Tags: des blog io ar os using Java SP files1.C3P0 IntroductionC3P0 is an open source JDBC connection pool that implements the data source and Jndi bindings, and supports the standard extensions of the JDBC3 specification and JDBC2. The open source projects that currently use it are hibernate,spring and so on.The core class of the C3P0 database connection pool is CombopooleddatasourceUse
First of all, what is C3P0? The following is the explanation of Baidu Encyclopedia:
C3P0 is an open source JDBC connection pool that implements the data source and Jndi bindings, and supports the standard extensions of the JDBC3 specification and JDBC2. The open source project that currently uses it has hibernate,spring
What are the advantages of using a connection pool co
Introduction
Database connection pooling: The database connection pool is responsible for allocating, managing, and freeing database connections, allowing applications to reuse an existing database connection instead of re-establishing one, and freeing up database connections that have idle time beyond the maximum idle time to avoid missing database connections due to no database connections being freed. This technology can significantly improve the performance of database operations.
Java conn
Databaseconnectionleak
connection leak Diagnostic method using C3P0 connection pool
Enable C3P0 connection return timeout setting
In the C3p0 property configuration file (0.datasource.config), set the following properties:
Debugunreturnedconnectionstacktraces=true
unreturnedconnectiontimeout=1200
Where: Debugunreturnedconnectionstacktraces is a switch, enabl
Original: http://www.mchange.com/projects/c3p0/#configuring_connection_testing
C3P0 provides a variety of methods for detecting failed connections, preventing programs from using invalid connections to complain. Connections fail for many reasons: JDBC driver actively shuts down long time connections, database or network reasons, insufficient resources, driver bugs, or other reasons.
First look at c3p0 this connection pool, the biggest advantage can automatically read the default configuration filedefault-config> //localhost:3306/swift_db default-config>There are general 4 main options and some other configurations in the configuration fileJust use the implementation class Combopooleddatasource in C3P0 to implement the Javax.sql.DateSource interface to create objectsprivat
1. CreateCom. mchange. v2.c3p0. combopooleddatasource
This is a JavaBean. Before use, set its jdbcurl, user, password, and driverclass. For other parameters, see configuration properties.
Combopooleddatasource CPPS = new combopooleddatasource (); CPPS. setdriverclass ("org. postgreSQL. driver ");
You can also use the name Configuration
Combopooleddatasource CPPS = new combopooleddatasource ("intergalactoapp ");
2. Use FactoryCom. mchange. v2.
The preferredtestquery attribute is ignored. You cannot perform any operation on this test table. It will only be used for c3p0 testing.. Default: NULL -->Retained, and continue to get the connection when getconnection () is called the next time. If it is set to trueAfter the connection fails, the data source is declared disconnected and permanently closed. Default: false -->Sqlexception. If it is set to 0, it will wait indefinitely. Unit: millisecond
Com.mchange.v2.c3p0.impl.C3P0ImplUtils Generatevmid Info: Failed to get local inetaddress for VMID. This was unlikely to matter. At all. We ll add some extra randomnessjava.net.UnknownHostException:Along.Fedora:Along.Fedora at Java.net.InetAddress.getLo Calhost (inetaddress.java:1353) at Com.mchange.v2.c3p0.impl.C3P0ImplUtils.generateVmId (c3p0implutils.java:120) at Com.mchange.v2.
Server mysql and c3p0 settings 1) interactive_timeout: parameter meaning: the number of seconds waiting for activity before the server closes the interactive connection. Interactive clients are defined as clients that use the CLIENT_INTERACTIVE option in mysql_real_connect. Default Value of the parameter: 28800 seconds (8 hours) (2) wait_timeout: parameter meaning: Disable the server
Server mysql and c3p0 s
Retained, and continue to get the connection when getconnection () is called the next time. If it is set to true, the connection pool is permanently interrupted after the number of attempts specified by acquireretryattempts still cannot be obtained. Default: false, all threads will wait for the connection pool to get the database connection -->
The preferredtestquery attribute is ignored. You cannot perform any operation on this test table. It will only be used for
XML version= "1.0" encoding= "UTF-8"?>C3p0-config> This is the default configuration information - Default-config> connecting four parameter configurations - Propertyname= "Jdbcurl">Jdbc:mysql://localhost:3306/customers Property> Propertyname= "Driverclass">Com.mysql.jdbc.Driver Property> Propertyname= "User">Root Property> Propertyname= "Password">123 Property> Pool parameter Configuration -
Initial sessionfactory creation failed.org.hibernate.service.spi.ServiceException: Unable to Create requested service [Org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] The configuration in the configuration file is such that,If a database connection in the connection pool is idle for more than the timeout time, it is purged from the connection pool andComment out this line and the error is gone.View Hibernate4.3.8 's Manual, as stated: not Intended for use with a production system
With the C3P0 connection pool, you do not need to parse the configuration file yourself, just create a profile with the specified name under the SRC folder.To create a project:C3p0.xml configuration file: C3p0test.java:Package Com.gordon.c3p0;import Java.util.list;import Org.apache.commons.dbutils.queryrunner;import Org.apache.commons.dbutils.handlers.arraylisthandler;import Com.mchange.v2.c3p0.combopooled
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.