Hi All,
I have an
EJB running on one machine and a
servlet running on the other machine. I want to cache the JNDI lookup, and most posts I read indicate to cache the InitialContext as well as the lookup. But does this make sense for an EJB3 stateless bean? Let me explain:
Most answers I see indicate to cache the context -- I agree
Context context = new InitialContext(env); // context gets cached
Most answers also state to cache the lookup, in this case, bean1
TestStatelessRemote bean1 = (TestStatelessRemote) context.lookup("TestStatelessRemote");
But... if bean1 is cached, and a particular method of bean1 takes a while to process, then any other
thread using bean1 will have to wait for that method to complete before any other method on the bean can be invoked.
Therefore it looks like I have to do a lookup everytime to get a new bean from the pool if other beans are busy.
So am I correct or incorrect? Should I cache bean1 or perform a lookup on it everytime?