Data source and database connection pool

Source: Internet
Author: User
Tags connection pooling

the data source in Java is Javax.sql.DataSource. The creation of DataSource can have different implementations. DataSource is often referred to as a data source, which contains two parts of connection pooling and connection pooling management, often referred to DataSource as a connection pool.

jndi mode creates DataSource: (Java naming and directory Interface,java naming and directory interfaces). First, you configure the connection information for the data source, which is the data source connection pool. This configuration should be configured in the Conf/context.xml file in the Tomcat installation directory .

  

Connection Pool basic idea, principle:

When the system is initialized, the database connection is stored as an object in memory, and when the user needs to access the database, instead of establishing a new connection, an established idle connection object is fetched from the connection pool.

The database connection pool is responsible for allocating , managing, and freeing the database connection , which allows the application to reuse an existing database connection instead of re-establishing one.

Connection Pooling Popular Understanding:

Database connection pooling is to prepare a pool, which contains a lot of generated good Connection, the user requests to get a connection, you do not need to getconnection, just take one from the pool to him, This eliminates the time to generate Connection , the efficiency will be greatly improved, but of course, will occupy some memory ~ slightly larger sites will use the database connection pool ~

Benefits of database connection pooling technology:

Resource Reuse

Faster system response Speed

New means of resource allocation

Unified connection management to avoid database connection leaks

Open source database connection pool c3p0 DBCP Proxool Xapool etc.

Take C3P0 to get the data source as an example:

@Test
public void Testc3p0 () throws exception{ combopooleddatasource CPDs = new Combopooleddatasource (); Cpds.setdriverclass ("Com.mysql.jdbc.Driver"); Loads the JDBC driver cpds.setjdbcurl ("Jdbc:mysql:///atguigu"); Cpds.setuser ("root"); Cpds.setpassword ("1230"); System.out.println (Cpds.getconnection ()); }

  

Data source and database connection pool

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.