- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
通过 SessionFactory.getCurrentSession()
获取 Hibernate session 是否线程安全?假设我有一个 static SessionFactory
对象用于我的整个应用程序,并且我有 5 个并发请求正在向我的 servlet 发出。我的 servlet 为每个请求调用方法 Auth.checkLogin()
,然后 Auth.checkLogin()
依次通过静态 factory.getCurrentSession 获取 session ()
。
在对我的 servlet 的每个请求结束时,transaction.commit()
将在之前获得的 session
上调用。
我的问题是,这是线程安全的方法吗?或者我应该做任何改变吗?
最佳答案
来自 Hibernate 4.0 SessionFactory
The main contract here is the creation of Session instances. Usually an application has a single SessionFactory instance and threads servicing client requests obtain Session instances from this factory.
The internal state of a SessionFactory is immutable. Once it is created this internal state is set. This internal state includes all of the metadata about Object/Relational Mapping.
Implementors must be threadsafe.
那么
Is it thread safe to obtain a Hibernate session via SessionFactory.getCurrentSession()?
对于 api 所说的,是的。
关于java - SessionFactory.getCurrentSession() 线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22030448/
我是一名优秀的程序员,十分优秀!