File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Stateful session bean applications. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Stateful session bean applications." Watch "Stateful session bean applications." New topic
Author

Stateful session bean applications.

Arun
Ranch Hand

Joined: Oct 03, 2003
Posts: 40
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

Joined: Aug 18, 2005
Posts: 372
Online Shopping. How would you implement a shopping cart?
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Arun
Ranch Hand

Joined: Oct 03, 2003
Posts: 40
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

Joined: Sep 29, 2002
Posts: 1683
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

Joined: Jun 30, 2004
Posts: 186
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.


Drinking more tea is the key...
 
GeeCON Prague 2014
 
subject: Stateful session bean applications.