• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateful session bean applications.

 
Arun
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am trying to think of an application or some scenarios where I would use stateful session beans. I know that when I need to maintain state I need staeful bean, but a more real world example would help me understand better. Almost always I feel a stateless session bean would suffice. Could someone who has used stateful session beans give me an example of where you used stateful session beans?

THanks.
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Online Shopping. How would you implement a shopping cart?
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An HTTP session would normally be a good alternative for session management for web apps.

It's generally true to say that there usually is no pressing case to use SFSBs and that you would use SLSBs in most cases.
 
Arun
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satish and Roger. As Roger says, I would implement a shopping website with SLSB's. Store the items a shopper adds to a http session and finally when he checks out, call a business method on a SLSB to do all the business logic. If i took the SFSB approach, for every item the shoppers adds to his cart I would be making RMI calls to some method in the SFSB, which is not that efficient.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another good reason to use HttpSession is that when a session is invalidated, you can do a cleanup in the valueUnbound() method should you have implemented the HttpSessionBindingListener interface.

Back to session beans: the big benefit of SLSBs is performance as they are pooled on server startup (and reused after the EJB method calls end), whereas SFSBs are created on client demand and are destroyed after use.
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would also use stateful SBs where it would be more expensive to re-create the state in a stateless SB for each method call - a poorly implemented stateless SB can be considerably less scaleable than a well implemented stateful SB.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic