1. This approach is time consuming task, since this is including the time taken for opening the
database session (connection) & closing the database session into request processing time.
2. This approach reduces the availability of the resources (database connections).
3. Decreases our system performances.
Solution to the above problem is given in the form of Connection Pooling.
Q .What is Connection Pooling?
- It’s a process of creating and storing database connections into buffer (or) a pool.
- A low-Level service offered by the corresponding server is called Connection Pooling.
Q .What is Connection Pool?
Set of equal database connection objects, is nothing but Connection Pool.
1. In case of Connection Pooling, no need to place any resource allocation logic & de-allocation
logic in our application.
2. In this approach, unused connection instances automatically retained (sent back) back to the
pool.
3. Retained connection objects are available to other remaining applications i.e.., Connection
Pooling provides reusable connection objects.
4. If we use Connection pooling mechanism, in designing of our application than our application
performance automatically getting increased.
Q.How to maintain communication with third-party vendor (server) provided Connection Pool
Using DataSource type of object .
It is an interface from SUN(oracle),which provide a standard abstraction to main communication with
third-party vendor provided Connection Pool’s.
By using DataSource interface implementation class object, we are allowed to collect required
database connection insatances from Connection Pool.
DataSource is available in (javax.sql.DataSource).
Q.How to collect the DataSource interface implementation class object ?
To collect this object, we can use
- JNDI LookUp.
- Resource Dependency Injection (introduced in JAVA EE 5.0).
-- pushing approach.
--@Resource annotation.
Connection Pool contains physical Connection objects.
Java Application Pool contains logical Connection objects.
- Pooled Connection: -A Connection object which resides inside the Connection Pool & it directly
interacts with the Database.
- Logical Connection:-A Connection instance which is not directly interacting with database.
When connection.close() is called, there is no relation b/w pooled connection & logical
connection, but there is a relation b/w database & pooled connection.
From one-pooled connection, we can obtain only one-single logical connection.
If we don’t specify connection.close(),(unused connection instances automatically retained back).