Stateless EJB with more injected EJBs instances

孤街醉人 提交于 2020-06-12 08:46:10

问题


I know Stateless EJBs are stored in a pool and instantiated as needed, my question is, what happens when there are more EJB dependencies, for example with something like this:

@Remote
@Stateless
public class Master_EJB{
     @EJB
     private EJB_A ejb_A;

     @EJB
     private EJB_B ejb_B;
}

With EJB_A and EJB_B also being stateless EJBs.

In the worst case, if there are two petitions at exactly the same time, the server will retrieve two instances of Master_EJB from the pool (or create if needed).

But if from those two calls, one only needs the EJB_A and the other only the EJB_B, how many instances are needed: 4 (2 Master_EJB + 1 EJB_A + 1 EJB_B) or 6 (2 Master_EJB + 2 EJB_A + 2 EJB_B)?


回答1:


EJB_A and EJB_B are stateless or stateful?

If stateless, answer depends on container/pool type used and recent situation (number of requests, server load and so on). If stateful and container will instantiate 2 Master_EJB instances, then two instances of EJB_A will be instantiated and also two instances of EJB_B will be instantiated.

Please bear in mind that container may create two Master_EJB instances - it depends on container itself and the current situation again (as well, container may decide to process request using only one Master_EJB instance).



来源:https://stackoverflow.com/questions/7256441/stateless-ejb-with-more-injected-ejbs-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!