| Author |
stateless vs stateful session beans
|
Rajiv Chelsea
Ranch Hand
Joined: Jun 15, 2010
Posts: 88
|
|
Please explain me the difference between stateful and stateless session beans?
Also it would be more helpful if i can get scenarios when to use stateful or when to use stateless , with respect
to a web application
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
The difference is just that one has state, the other doesn't. This means that every call to a stateless bean is distinct. The EJB session is analagous to an HttpSession (which you are maybe familiar with?) so its just a way of storing data in memory that pertains to a specific user. Make any sense?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Ram Narayan.M
Ranch Hand
Joined: Jul 11, 2010
Posts: 244
|
|
Stateless Session bean has pool of instances whereas Stateful does not have...
Stateful Session bean instances are created for each Client on the fly... So Client state information can be saved and can be used for next business method call..
In Stateless beans, Only one bean instance serves all the Client... So, in next business method call, bean does not have the trace of past information...
|
SCJP 6 [SCJP - Old is Gold]
|
 |
Rajiv Chelsea
Ranch Hand
Joined: Jun 15, 2010
Posts: 88
|
|
Hi Ram
In your reply you told , Stateless Session bean has pool of instances ..
Then again you say that Only one bean instance serves all the Client..
If only one bean instance is supposed to serve all the clients, then why is a pool of instances required?
Also it will be better if I can get an example of a scenario where to use stateful session bean
and where to use stateless session beans with respect to a single web-application
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
In Stateless beans, Only one bean instance serves all the Client...
This isn't right. There could be 1, or more instances (up to the number in the pool)
|
 |
Rajiv Chelsea
Ranch Hand
Joined: Jun 15, 2010
Posts: 88
|
|
|
Can any provide examples please?
|
 |
Ram Narayan.M
Ranch Hand
Joined: Jul 11, 2010
Posts: 244
|
|
|
If you want to display a list of books borrowed by particular customer of a library, giving the customer name as a key, List of books can be returned from stateless session bean method... This is an example of doing Bean managed persistence where querying Database are done by Stateless session bean itself... A search key is given and in return the result corresponding to that key is returned...
|
 |
 |
|
|
subject: stateless vs stateful session beans
|
|
|