• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between stateful & stateless

 
Suhas Madap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When we read the difference between the stateful & stateless session beans, the common answer we get is "that stateless bean will not store state of the client, where as the stateful will maintain the state of the client".

But my question is:
what do we exactly mean by "State"?

It would be so kind, if can explain, by giving a real world application.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

what do we exactly mean by "State"?


State is the information pertaining to the user/customer who is interacting or about to start interacting with the system.

Some examples would be his loginid, password, language, locale etc. In case of a shopping cart (a best example everyone follows) whatsoever the items the logged in user has been putting in the cart also constitutes the state of the bean to which the customer is tied with.

Hope this helps.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine that your client is getting a bean, and calling one of its business methods once. Then it decides to call it again. What if the bean needs to know that the client has already called it ? You want to keep the state of the conversation between the client and the bean. Stateless beans are used when you don't care about that. You get the bean, call its methods, that's all.
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing i will like to tell in this context is :
If you have an instance variable in your bean,then
1.If your bean is stateful,it will retain the value of instance variable for you,means, if you are trying to access that in some other bean,you will definitely get your value.
2.If your bean is stateless,you can't be sure that you will get the same of that instance variable.Because,stateless beans are taken from pool and after execution goes back to pool.

Hope this helps!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!