The relationship between DataSource drivermanage Connection pool

Source: Internet
Author: User
Tags connection pooling
The data source (DataSource) is the data source, call Datasource.getconnection () to get a connection without caring which database to connect to, user name/ What the password is. This is much more advanced than the Drivermanager.getconnection (URL, user, password). We use this datasource.getconnection () method to figure out what is the data source and connection pool.


There are two ways to implement DataSource


1. Direct-Attached database method
1. When calling Datasource.getconnection (), it actually calls the Drivermanager.getconnection (URL, user, password) to get a connection, Connection is close after use, disconnected from the database, we call this the total direct-attached database, because each need to re-establish the connection between the database, and did not leave the previous connection for the next use.




2. Pooling Connection mode
1. It can be said that this approach is the use of connection pooling technology. The DataSource internally encapsulates a connection pool, and when you get the DataSource, it has knocked out multiple connection with the database and put these connection into the connection pool, Call Datasource.getconnection () at this time to fetch a connection from the connection pool, connection is close after use, but this close is not really disconnected from the database, but rather tells the connection pool "I" has been used, "You" can assign me to other "people" used. In this way, the connection in the connection pool is recycled to avoid reconnecting the database each time the connection is acquired.
The two implementations of DataSource have been introduced, and now we know that the relationship between DataSource and connection pool is not the difference, because DataSource and connection pool is not the same type of things, only the same type of things are different, for example: O Racle and DB2 are databases, and they are different.


The relationship between the DataSource and the connection pool is: DataSource uses the connection pool cache connection to achieve the improvement of system efficiency and re-use of resources.


The connection pool can exist alone, without relying on datasource to get the connection, and you can directly invoke the method provided by the connection pool to get the connection.


At present, most application servers support the DataSource of pooled connection mode.


The common connection pool has c3p0,dbcp,proxool ...


General scene:jndi-> datasource-> connection pool (C3p0,dbcp,proxool, etc.)->drivermanager->connection




This article from the IT Training Evaluation Network (www.itpxpj.com), reproduced please indicate the source: http://www.itpxpj.com/course.do?method=getCourseInFront&courseId=133

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.