title: how is state of instance variables of a stateless bean preserved for next invocation in EJB?
body: <p>I am reading <a href="http://docs.oracle.com/javaee/7/tutorial/doc/ejb-intro002.htm#GIPNL" rel="noreferrer">Java EE7 documentation</a> and here is what it says for stateless bean. I am confused with what is meant by the statement  marked in bold below</p>
  
  <p><em>A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean's instance variables may contain a state specific to that client but only for the duration of the invocation. When the method is finished, the client-specific state should not be retained. <strong>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.</strong> Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client. That is, the state of a stateless session bean should apply across all clients.</em></p>
  
  <p>However from this post, 
  <a href="https://stackoverflow.com/questions/5643551/instance-variables-in-stateless-session-beans">instance variables in stateless session beans</a></p>
  
  <p><em>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.</em></p>
  
  <p>I feel that there is a contradiction here. The docs claim (from my understanding) that the instance variable state is preserved across next invocations while the latter post claims there is no guarantee that the state is preserved. </p>
  
  <p>please explain</p>
  
  <p>P.S: I did read this post: but I did not grasp the answer</p>
  
  <p><a href="https://stackoverflow.com/questions/5643551/instance-variables-in-stateless-session-beans">instance variables in stateless session beans</a></p>
  
  <p><strong>EDIT</strong> form the SO post above</p>
  
  <p>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. </p>