EJB design: differences between stateless and stateful session beans

  1. How to identify which is preferable stateless or stateful during design time.
  2. How to identify which is preferable stateless or stateful during design time.
    If you need state, go for stateful, if not, stateless
  3. 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.
  4. shoot down stateful bean[ Go to top ]

    try your best to do not use stateful except there is a good reason
  5. 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