Differences between JDBC connection pools and data sources and their performance

Source: Internet
Author: User
I have never figured out how the JDBC data source has the same relationship with the connection pool. When we were working on the system today, we encountered the problem of releasing the connection pool if we managed effective connections and resource usage.
The data source is not the same as the connection pool. It is not required to implement the connection pool, that is, the connection pool is a data source. The following online summary can be used as evidence:
In addition to improving performance and scalability, JDBC applications cannot see any difference between obtaining the datasource object to achieve connection pool and not obtaining. However, there are some important differences between application server and driver-level implementation.

A basic datasource implementation does not implement a connection pool, which is typically provided by the JDBC driver vendor. In the Basic datasource implementation, the following is true:

  • Datasource ?. The getconnection method creates a new connection object to represent a physical connection and encapsulate all installation and management work on the connection.
  • The connection. Close method closes the physical connection and releases related resources.

There are a series of major events behind the scenes in the datasource implementation including the connection pool. In the above implementation, the following is true:

  • Datasource? The implementation includes an implemented pooledconnection object that the specified connection pool module manages in a buffer zone. Datasource objects are typically implemented by the application server as a layer at the top layer of the connectionpooldatasource and pooledconnection interfaces implemented by the driver.
  • Datasource ?. Getconnection calls the pooledconnection. getconnection method to obtain the logical handle of a specified physical connection. The cost of creating a new physical connection will only occur when there is no available connection in the connection pool. When a new physical connection is required, the connection pool manager calls the getpooledconnection method of connectionpooldatasource to create one. The management of physical connections is performed by the pooledconnection object proxy.
  • The connection. Close method closes the logical handle, but the physical connection still exists. The specified pooledconnection object notified by the connection pool manager can be reused now. If the application tries to reuse the logical handle, the connection implementation will throw a sqlexception.
  • A single physical pooledconnection object will generate many logical connection objects during the life cycle. For a given pooledconnection object, only the newly generated logical connection object is valid. When the related pooledconnection. getconnection is called, any existing connection object will be automatically closed. The listener (connection pool manager) will not be notified of this event.
  • A connection pool manager calls the pooledconnection. Close method to close a physical connection. This method is typically called only in a specific environment: when the application server encounters a normal shutdown, when the connection buffer is being reinitialized, or when the application server receives an event that indicates that the connection fails to be restored.


Disable conection and statement. Otherwise, the usage of database cursors exceeds the limit due to the failure of the garbage collector to release resources effectively, and an sqlexception exception occurs.

Link:
Http://www.pgsqldb.org/twiki/bin/view/PgSQL/ConnectionPool documentation on connection pools

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.