无状态EJB中的静态vs实例成员 [英] Static vs Instance members in Stateless EJBs
问题描述
SLSB的自然方式是使每个实例独立,无静态,不需要实例之间的同步。因此,如果可能,我会有一个SLSB实例的工厂实例。
I have a stateless session bean which needs access to a factory class. Is it best to declare this factory class as a static or instance member in the SLSB? Am I correct in saying that, as SLSBs are reused, only one instance of the factory will be created per bean (when going with the instance member option), as opposed to one instance per request?
SLSB instances are pooled, and hence serve potentially many requests over their lifetime, so as you say instance variables are not recreated for each request.
The "natural" way for SLSB is to have each instance independent, no statics, no need for synchronisation between instances. Hence if it's possible I'd have a factory instance per SLSB instance.
这篇关于无状态EJB中的静态vs实例成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!