连接池的良好设计模式是什么? [英] What is the good design pattern for connection pooling?

查看:444
本文介绍了连接池的良好设计模式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实现一个连接(或一般资源)池的良好设计模式是什么?例如,一个tomcat服务器连接到一个mysql服务器,所有请求在tomcat服务器上共享一个mysql连接池。我搜索了一段时间,有人建议使用Singleton或把初始化代码放在一些静态块中。但其他人说单身人士是坏的。那么,什么应该是一个正确的设计模式用于连接池?感谢。

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.

推荐答案

对象(资源)池是一种设计模式

Tomcat中没有一个连接池, 定义多个池。然后,您可以通过服务提供者作为全局服务器,服务,引擎,主机或只是一个上下文。应用程序查找连接池,服务提供程序确保保留定义的规则。

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.

这篇关于连接池的良好设计模式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆