Thursday, March 1, 2012

how to use instance variable in stateless EJB

we can't keep client specific data in stateless session beans.

In a stateful session bean, the instance variables represent the state of unique client-bean sessions. The interaction of the client with bean is called as conversational state.

A stateless session bean is an object that does not have an associated conversational state, but may have instance state. It does not allow concurrent access to the bean. The contents of instance variables are not guaranteed to be preserved across method calls. All instances of a stateless session bean should be considered identical by the client.


Stateless Session Beans (SLSB) are not tied to one client and there is no guarantee for one client to get the same instance with each method invocation (some containers may create and destroy beans with each method invocation session, this is an implementation-specific decision, but instances are typically pooled - and I don't mention clustered environments). In other words, although stateless beans may have instance variables, these fields are not specific to one client, so don't rely on them between remote calls.

References:
http://www.geekinterview.com/question_details/15746
http://www.coderanch.com/t/487846/EJB-JEE/java/EJB-instance-variables
http://www.theserverside.com/discussions/thread.tss?thread_id=8330


A stateless session bean is an object that does not have an associated conversational state, but may have instance state.
It does not allow concurrent access to the bean.
The contents of instance variables are not guaranteed to be preserved across method calls.
All instances of a stateless session bean should be considered identical by the client


In a stateful session bean, the instance variables represent the state of unique client-bean sessions.
The interaction is of the client with bean is called as conversational state

http://en.wikipedia.org/wiki/Session_Beans

No comments:

Post a Comment