Create a C3P0 Data Source
When creating a C3P0 data source, there are very few connections to the database using JDBC in actual development. Generally, the data source is used. C3P0 is an open source data source, and the actual project is used a lot:
1. Added support for maven.
c3p0
When the concurrency is large, the c3p0 connection pool displays the following exception:
Caused by: Java. SQL. sqlexception: an attempt by a client to checkout a connection has timed out. at COM. mchange. v2. SQL. sqlutils. tosqlexception (sqlutils. java: 106) at com. mchange. v2. SQL. sqlutils. tosqlexception (sqlutils. java: 65) at com. mchange. v2.c3p0. impl. c3p0pooledconnectionpool. checkoutpooled
Spring uses annotations to configure C3P0 connection pooling and DAO use JdbcTemplate
1.Spring Configuration c3p0 Connection pool
Step one: Import the C3P0 jar package
Jar Package Download
Step Two: Create the spring configuration file and configure the connection pool
This is what we write when we write the C3P0 conn
Tags: database connection pool DBCP c3p0 Javac3p0 is an open source JDBC Connection pool that implements the data source and Jndi bindings to support the standard extensions of the JDBC3 specification and JDBC2. The open source projects that currently use it are hibernate,spring and so on. C3P0 data sources are used more in project development.1. c3p0 Difference
, not really shut down, but put it in an idle queue.) Release the connection if the number of actual idle connections is greater than the number of initial idle connections).(6) Release the database connection pool object (during server stop, maintenance, release the database connection pool object, and release all connections).Implementation principle:Baidu Encyclopedia has detailed records, I tell the words may not so that you can see the understanding (limited capacity).
1. Importing the JAR PackageC3p0-0.9.1.jarmchange-commons-java-0.2.3.4(Note: The jar package is a C3P0 database connection pool of auxiliary packages, no this package system will be reported when the boot ClassNotFoundException, This is the c3p0-0.9.2 version after the separation of the package, 0.9.1 when a package will be done)2. Get the connectionC3P0 is implemented in three ways.1. Write your own code t
The storage location of the first node in the list is called the head pointer, so the entire list must be accessed from the beginning. Each subsequent node, in fact, is the position that the previous successor pointer points to.
Here is a place to pay attention to, is the concept of the right pointer, this is very important. The storage location of the first node in the list is called the head pointer, and
C3P0 jar Package and configuration file download address: Click to open the link 1c3p0 introduction
C3P0 is also an open source free connection pool. C3P0 is favored by many people. the use of 2c3p0
The pool class in C3P0 is: Combopooleddatasource.
public void Fun1 () throws Propertyvetoexception, SQLException {
comb
Label:MySQL Default one connection idle 8 hours will automatically disconnect, and then the program thought the connection can also be used, and then in use will appear communications link failure exception. You need to set up two steps at this point, sometimes just set up MySQL. One, add the following two lines in the MySQL configuration file (the Linux configuration file is a my.cnf,windows profile of My.ini) (the default value is 28800, the following value represents one year.) I heard that M
Tags: blog com cti Trace Direct driver Common nbsp remI. Encapsulating the database connection (similar to DBCP) 1. Download Https://sourceforge.net/projects/c3p0/?source=typ_redirect 2. Import jar Mchange-commons-java-0.2.11.jar C3p0-0.9.5.2.jar 3, write the configuration file C3p0-config.xml XML version= "1.0" encoding= "UTF-8"?>
now Tomcat is using the default Apache DBCP connection pool for the company framework. This kind of connection pool is from the Noble Apache Foundation. But the word of mouth is not very good, in the new version of Hibernate has abandoned the support for DBCP, replaced by C3P0. At first I also had hope for DBCP, plus various parameter settings, but none were valid. Later changed on the C3P0, using its testc
First, c3p0 downloadC3p0:http://sourceforge.net/projects/c3p0/files/?source=navbar A compressed package is obtained after the download is complete.Ii. Configuring a Jndi data source using C3P0When configuring a Jndi data source in tomcat6.x, the default is to use the tomcat6.x dbcp connection pool, tomcat6.x Configure the Jndi data source with the DBCP connection pool as follows:1 If you want tomcat6.x to
C3P0 database connection pool,
Use the C3P0 database connection pool
1. Copy jar package: c3p0-0.9.1.2.jar c3p0-0.9.1.2-jdk1.3.jar c3p0-oracle-thin-extras-0.9.1.2.jar (oracle required)
2. Write the preparation file under the src directory:
1 C3P0 IntroductionC3P0 is also open source free connection pool! C3P0 is favored by many people!2 Use of C3P0Package Com.cug.c3p0;import Java.beans.propertyvetoexception;import Java.sql.connection;import Java.sql.sqlexception;import Org.junit.test;import Com.mchange.v2.c3p0.combopooleddatasource;public class C3P0Demo {@Testpublic void Fun1 () throws Propertyveto
Label:db.properties
jdbc.user=root jdbc.password=admin Jdbc.driverclass=com.mysql.jdbc.driver Jdbc.jdbcurl=jdbc\:mysql\:///spring4 jdbc.initialpoolsize=5 jdbc.maxpoolsize=10
in Spring.xml
--
Test Code:
public class Test { public static void Main (string[] args) { applicationcontext ctx = new Classpathxmlapplicationcontext (" Beans.xml "); DataSource DataSource = (DataSource) Ctx.getbean (" DataSource "); System.out.pri
Create a C3P0 data source,
[Author]: kwu
When creating a C3P0 data source, there are very few connections to the database using JDBC in actual development. Generally, the data source is used. C3P0 is an open source data source, and the actual project is used a lot:
1. Added support for maven.
2. Configure C3P0, the
Mysql Tomcat C3p0 System Performance Tuning personal summary
System Information
The application logic is to use c3p0 to query data in the database and return Json data over http.
1. the initial test result JMeter test result before optimization
No.
Type
Original
1000 data bigger
1
500 Connection
250 query/S
63q/S70q/S
2
1000 connections
255q/S
57q/S65 q
Reprint: http://www.cnblogs.com/haogeBlogs/p/5856302.htmlThe most common open source data connection pools are c3p0, dbcp, and Proxool, with three of them:The Hibernate Development Group recommends the use of c3p0;Spring Development Group recommends the use of DBCP (DBCP connection pool has WebLogic connection pool the same problem, is forced to close the connection or the database restart, cannot reconnect
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.