EJB design: differences between stateless and stateful session beans
How to identify which is preferable stateless or stateful during design time.
- Posted by: anil konduru
- Posted on: March 22 2007 02:45 EDT
- Re: differences between stateless and stateful session beans by John Smith on March 26 2007 23:40 EDT
- Re: differences between stateless and stateful session beans by piotr chojniak on March 27 2007 10:27 EDT
- shoot down stateful bean by Jacky Zheng on March 29 2007 22:40 EDT
How to identify which is preferable stateless or stateful during design time.If you need state, go for stateful, if not, stateless
Hi The difference is in maintenance of a state. When you use stateless session bean there is no state maintained during bean executions in opposition to the stateful session bean when the state is maintained during executions. If you have a requirement about the transaction that should span over two or more bean executions you should use statful session bean, otherwise use stateless session bean with the transaction that spans over the one execution of a bean.
try your best to do not use stateful except there is a good reason
Before selecting between the two, do think about State & Scalability. Stateful beans would be required when u want to maintain state acroos multiple requests to the EJB. But this can hamper SCALABILITY of your application. Stateless Beans can be seen as processes and used as Session Facades. This will help you to make your application more scalable as application servers maintain a pool of Stateless session beans to service client requests. But this will not provide you mechanism to maintain state which you can actually maintain in HttpSession if ur working on a webapp. So think about these two issues before selecting of the two and also luk for more issues & let us know about your findings in this thread. Thanks! Tarun