Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does Stateful Session bean store its state ?

 
pradeep arum
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
can somebody explain how this is done,can u give a simple example?
thanks in advance
Pradeep
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, both Stateless and Stateful beans can keep their state in instance or class (means static) variables.

like bean class :



For both Stateless and Stateful Session beans "a" variable will keep some value between calls.

The main difference is:

- For Stateful beans there is relation 1 client - 1 bean, so client invokes 5 times "doSomething" and get 5 in method "getA()"

- For Stateless beans there is a relation 1 client - many beans (they are taken every time from pool, and pool implementation is vendor specific), so client invokes 5 times "doSomething", but each call may be done on any bean instance (the same or different) and impossible to predict what method "getA()" returns.

In case static class variable, we can utilize state of stateless bean like this:





for any instance of stateless bean will be now 1 common reference to home interface among several calls.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic