0
votes

I did not understand about stateless session beans. The documentation says that the instances variables may contain client specific state and then says that when the method is finished the state should not be retained.

Lets say there is a method X and two clients called at the same time. The method X saves the client name in an instance variable. I see that there will be an issue when multiple threads call the same method simultaneously.

T1 accesses X and X sets the client name in a instance variable and sleeps. T2 accesses X and X sets the client name in a instance variable and sleeps. T1 resumes and X now sees T2's data.

Isn't this a problem? Or, does the container create a new instance for every client and destroys the ejb once the call is returned?

Secondly-- Clients may, however, change the state of instance variables in pooled stateless beans, and this state is held over to the next invocation of the pooled stateless bean.

Does this means that the same client can see its data across different method invocations? Or does it mean different client see each others data across method invocations?

1

1 Answers

1
votes

Isn't this a problem? No it is not, the second client will not get a reference to the same bean instance until the first one finishes its request (it has nothing to do with thread scheduling mechanism, it works on per request basis).

Does this means that the same client can see its data across different method invocations? Or does it mean different client see each others data across method invocations? True, for both of these questions, if the same instance of the bean is taken from the pool for the two different requests.