Meaningless Drivel is fun!
The moose likes Servlets and the fly likes HttpSession vs Stateless Session bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSession vs Stateless Session bean" Watch "HttpSession vs Stateless Session bean" New topic

HttpSession vs Stateless Session bean

Rowan John

Joined: Oct 12, 2003
Posts: 14
I would like to know why one would use a stateless session bean rather than a http session to track the 'session' of a browser based user? The only reason I can think of to use a stateless session bean is if I want to persist session-related information to a database.
Are there any other reasons, or is there something I'm missing?

thanks in advance,
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Well one other decision that might factor into this decision has to do with performance.
In the olden days, and maybe still today, keeping session information persistent would use up a little more memory, and be slow. Now they have definitely made improvements, but sometimes that performance hit was too much.
So by using a Stateless Session object, you had a pool of these objects that could act for any client, not just the one client that create the "Session". So in the one par twhere a session is persisten, each client must have it's own Session object and own it till the session ended. In a Stateless Session, this object is always either performing for a client, or in the Pool state ready to work for any other client that calls it. And if you really had to save the session, storing it in an Entity Bean or other persistent solution would be available.
So, what I am saying is it basically is a design decision based on what needs to be done, and what are the performance goals.
Hope that helps a little.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: HttpSession vs Stateless Session bean
It's not a secret anymore!