Hibernate的sessionFactory是线程安全的原因 [英] Reasons why Hibernate's sessionFactory is thread safe
问题描述
一个SessionFactory的内部状态是不可变的。大多数并发问题都是由于共享可变状态的对象。一旦对象是不可变的,它的内部状态就会在创建时被设置,并且不能被改变。
然而,Session是一个非线程安全的对象,您不能在线程之间共享它。
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 ?
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.
这篇关于Hibernate的sessionFactory是线程安全的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!