• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clear difference between stateless and stateful beans

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know stateful beans maintains state of object between multiple clients.
But what does this exactly mean.
**I think:
##Stateless beans gives problem in case of global variables and may cause data intermixing while stateful bean will not give problem in case of global variables and each client will get its own set value of global variables.
**Please clarify it and give me the exact difference between stateless and stateful beans???
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateful session bean holds the conversational states with the CURRENT client.

The Stateless session bean hold states (if you define instance variable in your bean class) but these states are not the conversational states with the CURRENT client.
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plz tell in language of coding
thanx
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know what you mean by gloabl variable..It is abstract word.. In java world you can have different kind of variables. e.g local(local to method), instance(object level), static(class level, common to all objects)..etc..
I assume your meaning of gloabl variable as instance variable.
You cannot have instance variables in stateless session bean. Though compiler doesnt complain about this, your data is going to be mess with this.
Stateless SB is going to be reused for all clients from the pool. If you call one method from SLSB(statelsess sessionbean), next method call may not go to same bean. Say for e.g, you have set some value, specific to you, inside SLSB with your first method call and if that bean is served for different client, that client will see that unexpected data which is set by you..
So in general we are not supposed to have instance variables in SLSB.
Stateful session bean do not have that problem as that is tied to you and it will not be served for others in its life time..
HTH.
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for reply.
That was what i was expecting.
Thanx for it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic