[Solved] Reasons why Hibernate’s sessionFactory is thread safe

I learned that Hibernate’s session factory is said to be thread safe. Can anyone articulate on how it acts as thread safe in a web application and how all methods are synchronized or anything else ?

Enquirer: Murali

||

Solution #1:

The internal state of a SessionFactory is immutable. Most problems with concurrency occur due to sharing of objects with mutable state. Once the object is immutable, its internal state is setted on creation and cannot be changed. So many threads can access it concurrently and request for sessions.

However, Session is a non-threadsafe object, you cannot share it between threads.

Respondent: Juliano Alves

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.