Introduction and definition of Java database connection Pool A simple connection pool

Source: Internet
Author: User
Tags connection pooling

Introduction and definition of Java database connection Pool A simple connection pool

What is a connection pool

Java uses JDBC to manipulate the database, we usually encapsulate the code of the JDBC duplicate into a Dbutil tool class, but in this case, because each operation of the database needs to establish a connection and release the connection, will cause a lot of resource consumption, when the Web application has a large number of users to access, This is going to be a very serious problem.

Therefore, in order to reduce the performance overhead, introduced the concept of connection pooling, that is, the connection with the database into a container, when the program needs to use the connection to the container request instead of establishing a connection to the database, release is also put the connection back to the container, rather than close the connection, in fact, there are some places in Java also "pool The concept, the normal volume pool, the thread pool, are to improve the efficiency of the program running, interested can be understood under.

How to customize a connection pool

    Java provides an interface Java.sql.DataSource, for the user to define a connection pool, if we want to customize a connection pool, then we can implement this interface, nonsense, directly paste code

This is because I'm just doing a simple connection pool for practiced hand, so there's no implementation of the DataSource interface, just a way to get the connection and put it back. There are a bit more comments, so maybe the code looks a bit long

      

    

With connection pooling, you can modify the access and release resources directly in the original dbutil.

  

Originally wanted to use the current commonly used connection pool Code also came out, but it seems a bit long, so we open a separate "room"

For any doubts or errors in this article, please comment below the article,

I buckle 3592867153, Network name and blog account name consistent

New registration of a number, for learning and communication, welcome you to guide the next

Introduction and definition of Java database connection Pool A simple connection pool

Related Article

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.