There is nothing technically stopping a Stateful Session EJB from being pooled but it does not make sense to do so. Pooling will not offer any advantages since the state of the EJBObject would need to be passivated to place it back in the pool. Rather than helping performance, this would hinder performance. For this reason Stateful Session EJBs are not pooled by any Application Server that I know of.
Joined: Oct 17, 2001
I read Master EJB and got a impression that stateful session bean can be out in instance pool,but the Enterprise Javabean said it can't be pooled. I am a little confused there. can you one give the good explaination? thanks.
Stateful Session Beans can be pooled. They just have to be treated differently then Stateless Session Beans. This is why there is a way to passivate and activate a Stateful Session Bean. Passivation/Activation is expensive and the Container definitely desires to passivate and activate as little as possible.
"Stateful Session Bean are dedicated to one client for their entire life, so there is no swapping or pooling of instances. Instead of pooling instances, stateful session beans are simply evicted from memory to conserve resources. ... This means that a stateful bean must be passivated beforeit is evicted to preserve the conversational state of the instance, and it must be activated to restore the state when the EJB object becomes active again." Page 266 Chapter 7 Session Bean Richard Monson Haefel
I hate to play the quote game but when you do, go straight to the source. Enterprise JavaBeans 2.0 Specification:
The container manages the life cycle of the session bean instances. It notifies the instances when bean action may be necessary, and it provides a full range of services to ensure that the session bean implementation is scalable and can support a large number of clients.
To efficiently manage the size of its working set, a session bean container may need to temporarily transfer the state of an idle stateful session bean instance to some form of secondary storage.
Hey guys this is what is commonly known as resource pooling. No where does it state that these actions are restricted to stateless session beans only. Now a quote from Mastering EJB:
EJB does indeed support the effect of pooling stateful session beans. Only a few instances can be in memory when there are actually many clients. But this pooling effect does not come for free - the passavation/activation steps could entail an input/output bottleneck. Contrast this to stateless session beans, which are easily pooled because there is no state to save.
[ April 18, 2002: Message edited by: Chris Mathews ]
Joined: Apr 11, 2002
Chris, sometime the book ,"Master EJB", is confusing. From life cycle of stateful beans, it is difficult to understand how stateful beans get pooled. By the way, maybe EJB1.1 and EJB2.0 are different.
Joined: Dec 07, 2000
1. Does Container manages instances of stateful session bean and assigns instance as and when request comes ? 2. Does the passivated instance of the bean is used to serve the other requests ? My answer to both is "No". Hence I do not think that stateful session Bean are "POOLED". Passivating Stateful session bean reduces the memory utilization on the server. I think it does not indicates that the passivated instance of the bean is re-used to serve another request. Let's Discuss.