A method for implementing the database connection pool (2)

Source: Internet
Author: User

The second is the onfactory class of the connection pool, which maps a connection pool object to a name. The user can obtain the specified connection pool object through this name. The specific code is as follows:
/**
* Connection pool factory, which is often used to store the hash of multiple data source names in combination with the database connection pool
* @ Author liusoft
*/
Public class ConnectionFactory
{
// This hash table is used to save the relationship table of the data source name and connection pool object.
Static Hashtable connectionPools = null;
Static {
ConnectionPools = new Hashtable (2, 0.75F );
}
/**
* Obtain the connection pool object with the specified name from the connection pool factory.
* @ Param dataSource name of the Connection Pool object
* @ Return DataSource return the connection pool object corresponding to the name
* @ Throws NameNotFoundException the specified connection pool cannot be found.
*/
Public static DataSource lookup (String dataSource)
Throws NameNotFoundException
{
Object ds = null;
Ds = connectionPools. get (dataSource );
If (ds = null |! (Ds instanceof DataSource ))
Throw new NameNotFoundException (dataSource );
Return (DataSource) ds;
}
/**
* Bind the specified name with the database connection configuration and initialize the database connection pool.
* @ Param name: name of the 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.