• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why use Stateful session bean as opposed to a HTTP session ?

 
Ranch Hand
Posts: 142
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
Why would I use a Stateful session bean at the application server level as opposed to a HTTP session at the web server level , basically does it really make sense to hold data at the application server level ? Is it worth the overhead of round trips to the application server ? Also stateful session beans are not as good at Stateless Session beans . Can some on give a real life example where Statefull session beans are actually better off than a HTTP session and statless Session beans .

Many thanks
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Click Here
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SFSB's are designed for managed client state over multiple calls to the same session bean (i.e. a conversation). If you look at JBoss Seam, you will see that there is very heavy use of SFSB's for conversation context.

In EJB3, there is no such thing as "stateless is better than stateful session beans". For example, one provides a service like a credit card processor (stateless) and one provides processing for a multi-screen wizard use case (stateful).

Managing state using HttpSession and stateless session beans is very difficult and problematic.

Read about Seam...
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use HttpSession then you have to worry about thread safety.Because HttpSession is not thread safe.But if you use Sessionfull beans you dont have to worry about thread safety.Because Sessionfull beans are not shared between different clients.
In future if you changes front end with some other front end then you have to maintain HttpSession in changed front again.
If you have transaction then it is better to use statefull session beans as compare to HttpSession.
In short HttpSession should be used for presentation layer not for business logic layer.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't count thread safety as a big point against HTTP sessions. That should be relatively easy to handle, especially in an application where most of the logic is part not of the servlet layer, but of the EJB layer.

But HTTP sessions rely on HTTP as the access protocol. As Gowher said, it can be used for the presentation layer, but not the business layer. Because the business layer may be also be used by non-HTTP clients (e.g., desktop applications or web services).
 
Meherdad Bomanbehram
Ranch Hand
Posts: 142
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys ,
So as long as my persentation layer is going to be for sure only the browser I would be fine using HTTP session but as we can never be sure of this and what happens the next day , I can see from the responses that its best to use stateful session beans .

Many Thanks
[ April 08, 2008: Message edited by: Meherdad Bomanbehram ]
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Correct me if I'm wrong but, in all case, you need to store the reference to the Stateful SB in a client session (HTTP for example) as each lookup to the Stateful SB returns a new instance.

For me, the great thing of EJB3 Stateful SB is the extended Persistence Context: you can do CRUD operations in a "wizard" way (the same conversation on many screens) and a commit/rollback at the end.
It's really easy.
reply
    Bookmark Topic Watch Topic
  • New Topic