• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

a question about Stateful Session Beans...

 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a shopping cart component (stateful session bean), but I'm confused with the concept, i guess..
When you work with HttpSession you can access the session object doing something like:

and you can access the session in any servlet, for instance, just by invoking the request.getSession..

Now, when I initialize my Session Bean, I do something like:

once I do this, i can invoke any method of my bean (add items, remove items, etc..). so far so good... but, if I get another request to a different servlet from the same client, for example, how do I get the reference to this session bean?
if I do home.create i will be creating another instance , right?
hope you guys understand...
thanks
 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you are in a different Servlet and you invoke create you get a diffent session bean coz the server considers you as a different client.If you want to access the same session bean you can place the session bean in the Http session object and get it back in the subsequent servlet using the get method.I am not sure though of the performance bottle necks this approach might induce.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by william kane:
When you are in a different Servlet and you invoke create you get a diffent session bean coz the server considers you as a different client.If you want to access the same session bean you can place the session bean in the Http session object and get it back in the subsequent servlet using the get method.I am not sure though of the performance bottle necks this approach might induce.



thank you.. that's the approach I was following. So what's the point of having the session bean if you are going to use the HttpSession object anyway. So you create the session bean and put it in the session variable... now I'm confused.. I thought you can use either HttpRequest or Stateful Session Beans
 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Andres Gonzalez:


thank you.. that's the approach I was following. So what's the point of having the session bean if you are going to use the HttpSession object anyway. So you create the session bean and put it in the session variable... now I'm confused.. I thought you can use either HttpRequest or Stateful Session Beans


Hi Andres,
The http client for your application is NOT your bean client rather its your servlets in you web app that are clients for your EJBs.Therefore your HTTPSession needs to map to your EJB.
I still,cannot understand your query :-(
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks william...
I understand your point.. I also did some more research and found this articles...
http://www.onjava.com/pub/a/onjava/2001/10/02/ejb.html
http://www.theserverside.com/discussion/thread.jsp?thread_id=552
<extracted-from-article>

If your application server does not support HttpSession cache management -- and you need to control the total number of session-oriented instances in memory at any given time -- you should place the bulk of your session-oriented data in an SFSB instead of an HttpSession object. You will still need to maintain an HttpSession for each client, but the only item in the HttpSession should be a reference to the SFSB for that client. If the only item in the HttpSession object is a reference to the SFSB, the amount of memory consumed by each HttpSession object is minimal and cache management of these instances is not needed. The bulk of memory consumption will occur within the SFSBs, which have a standardized strategy for allowing a container to perform cache management.

For systems that do not have a servlet/JSP front-end, SFSBs should be used to track session-oriented state similar to the way a web-based system would use an HttpSession object. This was the primary intent of SFSBs when they were created.

</extracted-from-article>
My system will only have web clients.. So does this mean that I could've used only HttpSession instead of stateful session beans?
thanks again
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic