This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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?
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
Joined: Oct 03, 2003
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.
Joined: Sep 29, 2002
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.
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.