Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

Hibernate: What is the connection pool and why is the default one unsuitable for production?

I'm very unfamiliar with Hibernate and have just started working on a web app that uses it with a MySQL database. I notice that the community documentation tutorial states:

The built-in Hibernate connection pool is in no way intended for production use. It lacks several features found on any decent connection pool.

Can someone elaborate on this? What exactly is it missing and what are problems people have with the 'default' one? On googling I found a website here but it doesn't really explain the problems, just what you should be using instead.

question from:https://stackoverflow.com/questions/4880577/hibernate-what-is-the-connection-pool-and-why-is-the-default-one-unsuitable-for

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What is the connection pool and why is the default one unsuitable for production? Can someone elaborate on this?

Connection pooling is a technique to open/prepare/close connections. A connection pooling mechanism is a piece of software (component), to which you delegate the function of managing connections. Your application would just ask for a connection, use it, and deliver it back to the pool. The component is responsible for opening N connections and leave them ready for when your application asks. If a connection is stale, the pooling mechanism would then close it and reopen a new one. This represents a better usage of connections, as you don't need to wait for the connection to be established during the actual execution of your code and you don't have to worry about stale connections.

Hibernate doesn't really ship any real connection pooling mechanism. It provides an internal connection manager, which is very rudimentary. The reason is simple: almost (if not all) Application Servers (like JBoss AS) and Servlet Containers (like Tomcat) provides a connection pooling mechanism by default. Thus, your application don't have to worry about the details about it. It just asks the AS for a connection.

In my opinion, there are only two cases where you need to worry about connection pooling:

  1. You are dealing with a standalone application (which doesn't run inside a container)
  2. You are really expert in connection pooling and none of the existing suits your needs.

But in my experience, most people that uses an "external" connection pooling do so for lack of knowledge about connection pooling and lack of knowledge about their container.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...