Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasons why Hibernate's sessionFactory is thread safe

Tags:

hibernate

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 ?

like image 939
Murali Avatar asked Jan 10 '13 14:01

Murali


1 Answers

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.

like image 89
Juliano Alves Avatar answered Oct 19 '22 07:10

Juliano Alves