Stateless Session Bean member variable modification. If a client is calling two methods f1() and f2() of a Stateless SB, one after another, is it possible that if f1() modified some member variable of the bean it may reflect in method f2().

Jon Thorarinsson

Note that here is no guarantee that the variable still has the value, so don't rely on it.

Variables in stateless session beans should only contain state which can be used by any client instance and not state which is specifically stored for a specific client instance. The reason is because at any time between method calls on the bean, the container may throw the bean out of the pool of available beans and destroy it. A stateful bean should be used if this is required.

An example of a non-client-specific state in a stateless session bean is caching of resources that the bean needs, like a reference to another bean. State variables like that, which should really be the only allowed state member variables in stateless session beans, should be initialized in ejbCreate() and released (if necessary) in ejbRemove(). That way, when a buisness method finishes on the bean, the private variable will live on as long as the bean is allowed to live in the container's pool, and therefore it's a good chance that the initialization of the private variable (which is often expensive) will not occurr every time a buisness method is invoked on the bean.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact