Lesson - 27 : JDBC - Connection pooling in JDBC

preview_player
Показать описание
Why DataSource interface is introduced
If a java program wants to obtain a connection with a database then there are two options for the java program

The following are the major drawbacks of DriverManager class
1. DriverManager class takes atleast three or four seconds of time to open database connection in a network so it decreases the burden on or performance of java application.
2. To obtain a connection using DriverManager a programmer has to remember driver class name it's url and username, password so it increase the burden on a programmer.
3. DriverManager class opens a separate connection for each client so number of connections on database server will be increased so it's performance is decrease.
4. DriverManager opens non reusable connections with a database so it increase burden on database server.

Why connection pooling:
When we use driver manager or datasource the connection opened with a datasource is a non reusable. For each client if a new connection is opened then burden on database server will be increase so to reduce the burden on database server we use connection pooling.
What is connection pooling:
Connection pooling is a mechanism which makes a database connection as a reusable for more than one client so burden on a database server will be reduced. A connection pooling makes database connections as reusable. A connection pool contains set of pooled connections(reusable connections).

How connection pooling works:
1. A server administrator prepares a connection pool with a setoff connections and also a mediator object as DataSource object to access the pool.
2. An administrator stores DataSource object into JNDI registry (java naming directory interface) .
3. A java application reads DataSource object from JNDI registry andasks for a connection from a pool.
4. A DataSource object takes a connection from a pool and creates a proxy or logical connection do it and then sends the proxy connection to java program.
5. When a java program closes proxy connection the DataSource will done real connection back to the pool.
Рекомендации по теме