Hibernate/Spring: Lots (thousands) of open connections the database?

The bernate documentation describes how connection pools are established in bernate.

The bernate documentation describes how connection pools are established in bernate: bernate will obtain and pool connections using java.sql. DriverManager if you set the following properties: Table 3.1. Bernate JDBC Properties Property name Purpose hibernate.connection. Driver_class JDBC driver class hibernate.connection.

Url JDBC URL hibernate.connection. Username database user hibernate.connection. Password database user password hibernate.connection.

Pool_size maximum number of pooled connections and more importantly: bernate's own connection pooling algorithm is, however, quite rudimentary. It is intended to help you get started and is not intended for use in a production system, or even for performance testing.It would be worth checking if the values described in the documentation are being used, which would result in bernate managing the pool without delegating the pool management to a production-ready connection pool implementation. As far as the output of netstat is concerned, the number of connections and the reason for opening them are the most important criteria for deciding whether you have a problem at hand.

Usually production-ready pool implementations will open connections only when necessary, and will have the ability to shrink pool sizes as well. Additionally, connections may be dropped by such a pool manager if they are not in use. It would appear that from the number of connections that are in the TIME_WAIT state, the server is waiting for traffic from the client; this might be the case of physical connections not being dropped after they are no longer required.

All of the above observations have only one resulting suggestion though - use a connection pool implementation that is better than the default one, and whose performance characteristics are also well understood. You would get suggestions to use c3p0 or BoneCP, from a lot of people here. Update Based on the Spring bernate configuration posted, it appears that a datasource is used to obtain connections for The configuration of the underlying connection pool behind the datasource would therefore be in use.

Update #2 The updated Spring application context file, uses the DriverManagerDataSource from the Spring framework. Stating ad verbatim from the documentation: NOTE: This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

An important thing to note is that DriverManagerDataSource relies on the properties provided to it, to create the connection. And as stated in the documentation, it would be using the DriverManager instead of a JNDI bound DataSource to create the connections. An important point here is that the DriverManager usually returns physical connections to the database, unlike DataSources which return logical connection wrappers.

It appears (from the netstat output) that these physical connections are not being closed. Maybe, bernate is not closing the connections; but that is unlikely; you would better off using a better connection pool implementation that can be configured to have an actual pool of connection objects that never exceed the pool size.

I don't use hibernates pool, at least not by setting it in the configuration. – Erik Jun 17 at 14:39 @Erik, do take a look at the update. You might have to look at the rest of your Spring application context configuration file.

– Vineet Reynolds Jun 17 at 15:05 I updated my post with the cofiguration I am using – Erik Jun 17 at 16:48 @Erik, you'll find similar advice in a related StackOverflow question. Apparently, even DriverManagerDataSource isn't a production quality datasource backed up by a connection pool. – Vineet Reynolds Jun 17 at 16:57 Thanks a lot for your extensive explanation.

I think I am going to try c3po and let you know ... – Erik Jun 17 at 18:46.

The Hibernate documentation describes how connection pools are established in Hibernate.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions