• Post Reply Bookmark Topic Watch Topic
  • New Topic

state in stateful session bean

 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends
i am new to ejbs, i want to know how session is maintained in stateful session beans. I have done lots of programming in servlets and jsp using httpsession. but in ejb we are not using http protocol so httpsession can not be used.
thanx in advance
 
gowrish bhaskar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The session is maintained through SessionContext in statefullbean.
Gowrish
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The state for a stateful session bean is maintained as fields in the object.

If the container has to passivate the bean (maybe it has to make "room" for other more active beans), it might serialize the thing to a file on disk. Before the client uses it again, it will be deserialized and the bean activated. But all you care (as the developer) is that you wrote an object and the data is referenced by fields.
But think about why you are using stateful session beans. They can be misused and put a burden on the server.
Just because it has "session" in its name does not mean it is anything at all like the http session object. It is not a replacement.
I usually prefer to keep the ejb's api stateless, and let the client keep the state. If the client is a webapp, this means the client's state is in http session. If the client is a java program, it means keeping the state in that program's memory.
 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your response, what i understand is in servlet/jsp same instance serves many client hence instance variables can not be use to store client's information while in stateful session bean one instance serves only one client hence that bean can store client specific information in instance variable.
correct me if i am wrong.
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!