Stateless EJB with more injected EJBs instances
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;
@E开发者_如何学JAVAJB
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).
精彩评论