1

For a statful EJB, if I get its reference using InitialContext.lookup(itsMappedName), for each call of (InitialContext.lookup(itsMappedName)) it will return a new Stateful EJB or the same stateful EJB?

user1169587
  • 1,104
  • 2
  • 17
  • 34

1 Answers1

0
public class SFEJB implements EJBRemote{
  //.....
}

public class Class1{
  void method1{
    InitialContext ctx = new InitialContext(env);            
    EJBRemote testEJB= (EJBRemote)ctx.lookup(mappedName#fullclassname);
    //.....
  }
}

I find it will return a new stateful EJB (SFEJB) for each initialcontext.lookup(mappedName#fullclassname).
At first, I think "Stateful" in "Stateful EJB" means for the same web client, I will get the same stateful EJB for each call of initialContext.lookup(mappedName#fullclassname), but now I know the "Stateful" is just means for the testEJB, each method call will call to the same SFEJB instance(so in a state).
So testEJB is the EJB Client of SFEJB? (SFEJB remember testEJB)

user1169587
  • 1,104
  • 2
  • 17
  • 34
  • Oh, I find more complex, if the ejb is stateless, then each time the ctx.lookup(mappedName#fullclassname) return the same proxy!! is there any error?? – user1169587 Mar 07 '13 at 04:03