Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

usefulness of session beans

 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am trying to understand where there is a need to use Sessionbeans
( atleast in case of web applications )
My understanding is for web applications - I will save user state in HttpSession .

Now if I use HttpSession I wouldnt want to use Stateful session beans

I would use stateless session beans

Can someone explain a scenario in web applications where it would be useful .

Thanks ,
~satish
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateful session beans are useful if your application has state, but you have non-web clients. For example, if you have permissions set when you log in to an app and cahced with your principal and you need those permissions to be the same if you log in again through another app. Make sense?
 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul for your reply .

What I am a little sore at is - the books about ejb dont mention this point clearly and explicitly .

In the applications that I work in are almost always web applications so i think it would be safe to say bye bye to steful session beans !

Thanks ,
~satish
 
Scott Selikoff
author
Saloon Keeper
Posts: 4010
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateful beans are harder to maintain (from a coding stand point) which is why stateless session beans are implemented in practice more often. Often if state is needed its unloaded to a system management component; for example, storing data about a user's current session into a database. The advantage is that the data can be used for customer analysis and disconnected sessions, such as saving a user's shopping cart for future sessions.
[ August 05, 2008: Message edited by: Scott Selikoff ]
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateful session beans maintains conversational state. They are also pooled by the application server in which the session beans are deployed however it requires a lot of resource due to the fact that it has to be serialized when it is not needed and deserialized when it is being demanded by a particular request that is why most web applications use stateless session beans and maintain the conversational state in the session of the web container.
 
Sathish Nagappan
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jerwin Louise Uy:
Stateful session beans maintains conversational state. They are also pooled by the application server in which the session beans are deployed


As per my understanding, Stateful session beans are not pooled. They are created by the application server the first time the client creates a session with the EJB container. When the client is inactive, or between invocation of business methods, the Container has the freedom to serialize (passivate in EE terms) and activate (deserialize) Stateful session beans.

Stateless session beans however, are pooled and the same session bean object may service 2 different clients at different points in time without construction and destruction of the actual bean object. With stateful beans, each session from the client would work on a fresh Stateful session bean object.
[ August 06, 2008: Message edited by: Ashwanth Fernando ]
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the misunderstanding.

Well, technically the ejb container is achieving the "effect of pooling" through passivation and activation so that the same session bean will serve the same instance because it has to conserve resources.

Regards.
 
Sathish Nagappan
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerwin Louise Uy wrote:Sorry for the misunderstanding.

Well, technically the ejb container is achieving the "effect of pooling" through passivation and activation so that the same session bean will serve the same instance because it has to conserve resources.

Regards.


You misunderstand. There is no "effect of pooling". Pooling only comes into play when the same bean serves multiple clients without being deconstructed and reconstructed again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic