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 ?
Asked
Active
Viewed 2.8k times
1 Answers
11
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.

Juliano Alves
- 2,006
- 4
- 35
- 37
-
Moreover why sessionfactory is thread because of hibernate principle of single data source – LowCool Jan 12 '18 at 07:20