• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instance variables of a stateless bean is reset to default values?

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on this article : http://theopentutorials.com/tutorials/java-ee/ejb3/session-beans/slsb/introduction-11/,
it says
"instance variables can be used but the contents of those instance variables are not guaranteed to be preserved across different client method calls."


Does it mean the container will reset the instance variables of a stateless bean to default values after each client invoked method call?
JSR 318 does not explicitly say the container will do that.

I assume the client of the bean may update the instance variables in one method call.

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container will do no such "resetting" but for stateless session beans, the container does not guarantee that you'll get the same object instance of the stateless bean between multiple business method calls.
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, if the client set an instance variable in a stateless bean during one method invocation, the instance variable will be set to the new value forever?

The JSR 318 says
"all bean instances are equivalent when they are not involved in servicing a client-invoked method."


If an instance variable is updated by a client, then this instance is not equivalent to others in the pool.
What should we do then?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, if the client set an instance variable in a stateless bean during one method invocation, the instance variable will be set to the new value forever?

Unless it will be involved in another method call that sets that variable...

JSR-318 is clear about the term state:
The term “stateless” signifies that an instance has no state for a specific client. However, the instance variables of the instance can contain the state across client-invoked method calls. Examples of such state include an open database connection and an object reference to an enterprise bean object.

Bottom line is: don't use instance variables to keep state for a particulair client.

If an instance variable is updated by a client, then this instance is not equivalent to others in the pool.
What should we do then?

Don't use instance variables in a Stateless Session Bean.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic