开发者

Sharing Hibernate on multiple Tomcat instances

开发者 https://www.devze.com 2023-01-14 05:51 出处:网络
I have 4 we开发者_如何学运维b applications, that have a common reference to an Hibernate implementation but that run on different Tomcat instances. And so, for example, a connection pool configured in

I have 4 we开发者_如何学运维b applications, that have a common reference to an Hibernate implementation but that run on different Tomcat instances. And so, for example, a connection pool configured in Hibernate with a min size of 3 (with c3p0), will result in 12 connection open (3 for each instance) when all the projects are running .

I'd like to "share" the Hibernate implementation with the instances (and so to have always 3 connections open instead of 12), and I was wondering about the best solution to achieve it.

Any tips?

Thanks


I'd like to "share" the Hibernate implementation with the instances (and so to have always 3 connections open instead of 12), and I was wondering about the best solution to achieve it. Any tips?

This is not a good idea. In short, a connection pool should be sized to contain enough connections to serve incoming concurrent requests without having them to wait for a connection to become available. With 4 applications, you'll very likely need more than 3 connections. There is something wrong (or not clear) with your logic.

My tip would thus be to allocate enough resources and to size your thread pools and connection pools appropriately to serve the concurrent requests each application is supposed to handle, and this without exhausting the pool.

See also

  • Solving common Java EE performance problems


One approach could be to create an additional backend service which runs Hibernate and which is connected to the frontend services via a Web Service. This way there would be one Hibernate instance.


You can't do it. Each Tomcat instance runs in its own JVM, so you can't share object or classes between them.

Why don't you like 12 DB connections? Modern database systems are capable of handling millions of connections.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号