JDBC--Connection Pool

Source: Internet
Author: User

Connection pool:create many Connection objects in advance, and put the Connection into the cache (list). The client would get the connection from the cache, and return the Connectio to the cache after using it. This is the could improve the access effeciency of data base.

Simulate the connection pool:

 PackageCom.pp.pool;Importjava.sql.Connection;Importjava.util.ArrayList;Importjava.util.List;ImportCom.pp.util.JdbcUtil;/** Simulate the completion of Connetion pool*/ Public classSimpleconnectionpool {Private StaticList<connection> pool =NewArraylist<connection>(); Static {         for(inti = 0; I < 10; i++) {Connection conn=jdbcutil.getconnection ();        POOL.ADD (conn); }    }    //get the Connection object from the cache pool     Public synchronized StaticConnection getconnection () {if(Pool.size () > 0) {Connection conn= Pool.remove (0); returnConn; } Else {            Throw NewRuntimeException ("Server is busy!"); }    }    //Return the connection     Public Static voidReleas (Connection conn) {POOL.ADD (conn); }}

JDBC--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.