具有更多注入的EJB实例的无状态EJB [英] Stateless EJB with more injected EJBs instances
问题描述
我知道无状态EJB存储在一个池中并根据需要实例化,我的问题是,当存在更多的EJB依赖关系(例如,像这样的东西)时会发生什么?
@Remote
@Stateless
public class Master_EJB{
@EJB
private EJB_A ejb_A;
@EJB
private EJB_B ejb_B;
}
EJB_A和EJB_B也是无状态EJB.
在最坏的情况下,如果完全同时存在两个请求,则服务器将从池中检索Master_EJB的两个实例(或在需要时创建).
但是,如果从这两个调用中,一个只需要EJB_A,而另一个只需要EJB_B,则需要多少个实例:4(2个Master_EJB + 1 EJB_A + 1 EJB_B)或6(2个Master_EJB + 2 EJB_A + 2 EJB_B )?
EJB_A和EJB_B是无状态还是有状态?
如果为无状态,则答案取决于所使用的容器/池类型和最近的情况(请求数,服务器负载等). 如果有状态和容器将实例化2个Master_EJB实例,则将实例化EJB_A的两个实例,并且还将实例化EJB_B的两个实例.
请记住,容器可以创建两个Master_EJB实例-它再次取决于容器本身和当前情况(同样,容器可能决定仅使用一个Master_EJB实例来处理请求)./p>
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)?
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).
这篇关于具有更多注入的EJB实例的无状态EJB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!