无状态EJB中的静态vs实例成员 [英] Static vs Instance members in Stateless EJBs

查看:121
本文介绍了无状态EJB中的静态vs实例成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无状态会话bean,需要访问工厂类。最好在SLSB中将此工厂类声明为静态或实例成员?我正确地说,由于SLSBs被重用,所以每个bean只能创建一个工厂实例(与实例成员选项一起使用),而不是每个请求一个实例?



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆