Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing Hibernate on multiple Tomcat instances

I have 4 web 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

like image 885
Mark Avatar asked Aug 30 '10 18:08

Mark


2 Answers

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
like image 134
Pascal Thivent Avatar answered Nov 15 '22 21:11

Pascal Thivent


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.

like image 45
Timo Westkämper Avatar answered Nov 15 '22 21:11

Timo Westkämper