Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the good design pattern for connection pooling?

What is the good design pattern for implementing one connection (or generally resource) pool? For example, one tomcat server connects to one mysql server, and all the requests share a mysql connection pool on tomcat server. I have search for some time, some people proposed to use Singleton or put the initialization code inside some static block. But others said singleton is bad. So, what should be a right design pattern to use for connection pooling? Thanks.

like image 754
Geni Avatar asked Feb 13 '12 07:02

Geni


People also ask

Is object pooling a design pattern?

The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand. A client of the pool will request an object from the pool and perform operations on the returned object.

Which has the highest priority for creating connection pool?

Database connection pooling is still achieved through application module pooling. The only exception is when multiple application module pools (and therefore a large number of application module instances) share the same database, making the total available database connections the highest priority.


2 Answers

FlyWeight Design pattern used for Connection Pooling . as stated by GOF "Facilitates the reuse of many fine grained objects, making the utilization of large numbers of objects more efficient."

like image 125
user2361869 Avatar answered Sep 24 '22 22:09

user2361869


Object (Resource) Pool is a Design Pattern.

There is not a single Connection pool in Tomcat, instead it allows you to define multiple pools. You then control the scope and access to each pool via a service provider as either the global server, a service, an engine, a host or just a single context. The application looks up connection pool and the service provider ensures the defined rules are upheld.

However, your question it so open ended we cannot feasible suggest the most appropriate solution for you.

like image 26
Martin Spamer Avatar answered Sep 23 '22 22:09

Martin Spamer