@EJB injection vs lookup - performance issue

后端 未结 2 1513
南旧
南旧 2021-01-18 21:08

I have a question related with possible performance issue while using @EJB annotation. Imagine following scenario

public class MyBean1 implements MyBean1Remo         


        
2条回答
  •  感动是毒
    2021-01-18 21:41

    The container does not inject an instance of the EJB; it injects an instance of a lightweight container-generated proxy object that implements the desired interface.

    public class MyBean1 implements MyBean1Remote {
       ...
    }
    
    public class MyAnotherBean implement MyAnotherRemote {
       @EJB
       private MyBean1Remote myBean1;
    }
    

    In your example, MyAnotherBean.myBean1 will be injected with a proxy object that implements the MyBean1Remote interface.

    Assuming a stateless session bean (since you mention pooling), the container does not allocate an actual EJB instance from the method-ready pool until a method is called on the proxy, and the instance is returned to the pool before the proxy method call returns.

提交回复
热议问题