简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM