Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instance Variables State

 
Alibabra Sanjie
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can stateless session bean contain its state info across clients method invocations?
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alibabra Sanjie:
Can stateless session bean contain its state info across clients method invocations?

"Stateless" wouldn't be a very good description if it's state was preserved, yes?
--Dale--
 
Alibabra Sanjie
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I think so. Stateless session bean can keep the state info across client(s) methods, but not client specific
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, how does a stateless session bean maintain state after having been put back into the pool?
 
Tejas Bavishi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Yes, I think so. Stateless session bean can keep the state info across client(s) methods, but not client specific

I think I have seen this behaviour before. I guess stateless session bean instance variables can be thought of as a Java class static instance variables.
Tejas
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is true, what good would it be? Say we have a pool of 10 stateless session beans. That would mean we have 10 copies of this variable. Say I put some state in one of these 10. On the next call to a session bean of this type, at the container's whim, we may get a bean that we've had before (and "maintained state"), and maybe not. I just don't see what use it would be if you couldn't count on it.
--Dale--
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or that pesky container invokes ejbRemove() on some of the stateless session bean instances ...
 
Alibabra Sanjie
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...I just don't see what use it would be if you couldn't count on it.

Yes, we CANNOT rely on it. But we still can use it as transient instance variables, and be careful when they across methods
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alibabra,
I recommend that you do not carry this belief with you into the exam ...
 
Sujatha Kumar
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can stateless session bean contain its state info across clients method invocations?

A stateless session bean cannont contain its state info across method invocations except for static variables.
If the bean contains any static variable then the latest updated value will be made availalbe to all instances in the pool.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bearing in mind, of course, that the use non-final static fields is disallowed for an enterprise Bean. So, if anyone is looking to store variable data in static fields, they should think again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic