Connection pool in resin

xiaoxiao2021-03-06  14

The Database Section In Official Resin Documention Description as Follow Linked Here (http://www.caucho.xtp).

connection pool A set of connections maintained so the connections can be reused when there is a future need for the conneciton. Connection pools are used to reduce the overhead of using a database. Establishing a connection to the database is a costly operation. A connection that pool keeps a pool of open connections, each connection can be used for a time as needed, and then released back to the pool. A connection that has been released back to the pool can then be reused. Connection pooling is especially important in server applications .................................... ...Claizers. And the Reuse for Many Requests.

DataSource A JDBC Term (AND interface name) Used for a factory That Is Used to Obtain Connections. Resin provides Animentation of DataSource. Resin's Implementation of DataSource IS A Connection Pool.

Driver An implemetation of a defined interface that hides the details of communication with a device or other resource, such as a database. Driver provides an interface and is responsible for the communication with the database. Every different database (ie Oracle, MySQL) has their OWN Means of Enabling Communication from The Clism (in This Case Resin and You Applications) AND The Database. The Driver Provides A Common Interface That Hides The Details of That Communication.

Transaction A transaction is used to mark a group of operations and provide a guarantee that all of the operations happen, or none of them happen. Transactions protect the integrity of the database. Transactions are especially important in server applications where many threads of processing may be interacting with the database at the same time.Obtaining and using a database connection Getting the DataSourceThe DataSource is a factory that is used to obtain a connection. The DataSource is obtained using the specified when configuring the database resource.

Ideally, the JNDI lookup of DataSource is done only once, the DataSource obtained from the lookup can be stored in a member variable or other appropriate place. The stored DataSource can then be used each time a connection is needed. If it is not stored, There Will Be An Impact On Performance from Having to Do The Lookup Each Time You Want To Get A Connection.

Obtaining a datasource public class .... {private final static string DataSource_name = "jdbc / test"; datasource _pool; ... void init () {TRY {Context env = (context) new initialcontext (). Lookup ("Java" : comp / env "); _pool = (DataSource) env.lookup (dATASOURCE_NAME); if (_pool == null) throw new ServletException (" `" dATASOURCE_NAME " 'is an unknown DataSource");} catch (NamingException e ) {Throw new servletexception (e);}} ...}

Getting a connectiona connection is obtained from the datasource. The connection is buy with a call to close () So That Resin Knows it is available.

It is very important that the close () is always called, even if there as an exception. Without the close (), Resin's database pool can loose connections. If you fail to close () a connection, Resin does not know that it is Available for Reuse, And Cannot, Eventual, Resin May Run Out of Connections.always Put A Close () In a Finally Block, To Guarantee That Is Called.

.

Getting a connection from the datasource connection conn = NULL; try {conn = pool.getConnection ();

Statement Stmt = conn.createstatement ();

ResultSet RS = Stmt.executeQuery ("...");

...

Rs.close (); stmt.close ();} catch (sqlexception e) {throw new servletexception (e);} finally {try {if (conn! = null) conn.close ();} catch (sqlexception e) {}}

转载请注明原文地址:https://www.9cbs.com/read-48050.html

New Post(0)