Hi, I've tried to run a stateless session bean that holds the role of a counter (code is extracted from Howard Kushner's book Developping J2EE Application with IBM Websphere Studio) Here's the code of the bean:
Well, all is OK when I run this bean via the Universal test client. But, i'm not clear about something. As far as I have understood, in case of stateless beans, the same client won't necessary call the same bean through its different method calls. Or, when I call merely times the increment method via the UNiversal Test Client, the counter's value increment of one unit each time. It means 0 ->1 ->2 -> 3 -> 4. I would expect that the value will not increase so regulary and that I would have for example 0 -> 2 -> 1 (because the second time, the client would have asked for another bean instance). So, shall we conclude from this that only one instance of this stateless session bean is created by Websphere EJB container? Thanks for any light on this topic, Regards, Cyril.
SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287
Hi, Cyril, from that example, we can conclude that the container used only one bean instance to serve your client. But it may have more than one instances in the pool. You may put a print message to the setSessionContext or ejbCreate methods to know how many bean instances are created. This value may be configured in the app server.
Hi Cyril, One of the interesting point for stateless session bean is that, there will be a instance pool that hold by the container. When there are several requests coming in, the container picks up an idle bean to serve the requests randomly. If there are not enough idle beans to serve the requests, it will create more until it reaches the max. no. of instances. In your case, since there is always 1 request, it may not be surprised that there is only 1 instance created by the container to serve the request. If you write a multi-thread program and, say, call the bean 1000 times, you may get your expected outcomes. Nick.