Connection Pooling

  • Pool is a collection of reserved resources.
  • Same collection object can be reused multiple times.
  • If we required to communicate with database multiple times, then it is not recommended to create a separate connection object every time because and destroying connection object. Every time creates performance problems.
  • To overcome above problem, we use connection pool.
  • Connection is a pool of already created connection objects
  • We request connection to provide connection object object whenever we want to communicate with database. After completing our work, we return the connection back to the pool instead of destroying it.
  • Reusing same connection, object helps to improve performance
  • Implementing connection pool
    • Connection pool is implemented by creating a data source object like DriverManagerDataSource, HikariDataSource,ComboPooledDataSource(c3p0).
    • Data source is responsible to manage connections in the connection pool.
    • Driver vendor is responsible to provide implementation.
  • Driver Manager versus Data source object
    • When we create object from driver Manager, it always creates new connection object
      • Con=DriverManager.getConnection(url,name,pwd)
    • When we create object from data source, it provides connection from data pool.
      • Con=DS.getConnection();
  • Performance wise data source is a better approach.
  • Examples

No comments:

Post a Comment

Spring Boot

What is circular/cyclic dependency in spring boot? When two services are interdependent on each other, that is to start one service, we requ...