What is the good design pattern for connection pooling?

时光总嘲笑我的痴心妄想 提交于 2020-01-03 17:23:31

问题


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.


回答1:


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.




回答2:


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."




回答3:


I prefer singleton design pattern.

It will create Instance single time and Used frequently.

for timely connection pooling Singleton it will easy and good.



来源:https://stackoverflow.com/questions/9256758/what-is-the-good-design-pattern-for-connection-pooling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!