In this post we will talk about Why we need a database connection pooling.
Creating a network connection to a database server is expensive process. As creating new database connections is costly and it doesn’t make sense to create a new connection for each transaction that might only take a few milliseconds. Managing database connections in a pool means that applications can perform database transactions in a way that avoid the connection creation time (The connections still need to be created, but they are all created at start-up). The downside is that if all connections are in use, and another connection is required, the requesting thread will have to wait until a connection is returned to the pool.
Benefits of connection pooling as follows:
- Performance: Connecting to the database is expensive and slow. Pooled connections can be left physically connected to the database, and shared amongst the various components that need database access. That way the connection cost is paid for once and amortized across all the consuming components.
- Diagnostics: If you have one sub-system responsible for connecting to the database, it becomes easier to diagnose and analyse database connection usage.
- Maintainability: Again, if you have one sub-system responsible for handing out database connections, your code will be easier to maintain than if each component connected to the database itself.
In this database connection pool learning series, we are going to learn below list of connection pool using a demo project.
DBCP Connection Pooling Example
C3P0 JDBC connection pool Example
BoneCP connection pool example
Hikari Connection Pooling Example
That’s all about this topic Why we need database connection pooling?
If you have any feedback or suggestion please feel free to drop in blow comment box.