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.
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.
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.
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."
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With