Hibernate version: 3.1
Mapping documents: Irrelevant
Code between sessionFactory.openSession() and session.close(): get pojo, access collection
Name and version of the database you are using: Oracle
Hello,
i have a webapplication which uses one hibernate session per http user (with synchronized block to prevent 2 parallel hibernate request from same user) and use log running session pattern. So far so good. However, we find this very inefficient. Each user requesting data must do some calls to the database, and the datas are present in server memory in has much copies as there are http session. Because http session last for 8 hours, there can be lots of copies which each occupy about 20M of memory (150 "Employee" POJO/session * 150k picture/POJO = 21M / session). With about 30 sessions running at same time, we get 600M of hibernate data to store the equivalent of 21M raw datas.
Because 99% of user requests are read-only request (mainly, get list of phone numbers and picture of employees), we would like to share those pojo to all users, in a single application scope session. Now, we know the session is not thread safe, and we planned to make some synchronized block around sql request. But my question is, what will happen with lazy loading. If I share a read-only pojo with several thread, won't i get some troubles with lazy collection loading? Let's say Thread-A and Thread-B issue, at the same time a
Code:
pojo.getCollectionX().get(69).getSomeProperty(),
won't that cause troubles?