What is a good design pattern for pooling?

What is a good design pattern for implementing a single connection pool (or resource in general)? For example, one tomcat server connects to one mysql server, and all queries share the mysql connection pool on the tomcat server. I searched for a while, some suggested using Singleton or putting initialization code inside some static block. But others said singleton is bad. So, what should be the right design pattern for joining connection pools? Thanks.

+4
source share
3 answers

A pool of objects (resources) is a design template .

Tomcat does not have a connection pool; instead, it allows you to define multiple pools . Then you control the area and gain access to each pool through the service provider as a global server, service, engine, host, or just a single context . The application is looking for a connection pool, and the service provider ensures that certain rules are maintained.

However, your question, which he opened so, we cannot make possible the most suitable solution for you.

+3
source

FlyWeight design pattern used for the connection pool. as stated in GOF "Facilitates the reuse of many fine-grained objects, which makes the use of a large number of objects more efficient."

+2
source

I prefer the singleton design template.

It will create a one-time instance and is often used.

for timely pooling Singleton pool it will be easy and useful.

+1
source

Source: https://habr.com/ru/post/1396135/


All Articles