• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem in understanding session beans

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I am a novice in ejb and I am finding it very hard to understand stateful and stateless session beans. As we all know stateful session beans are used when we want to maintain a state. Here as per my understanding is maintaining a session by the container. Such as what all activities are being done in a particular session.

To implement this I made a very small program of stateless and stateful session bean and connected this ejb module with struts via Guice DI framework.

The following is my stateful and stateless code:-






Here both the interfaces are remote.


My problem is:-
Whenever I call a struts action method method which internally calls the stateless session bean from one particular browser the bean is initialized (only once for one browser) and the value of i is incremented by 1. This increment happens each time i call the bean method. If i call stateless session bean from another browser a new stateless session bean is created, and its postconstruct method is executed and the value of i is initialized.

However when i call a method that calls the stateful session bean, each time i call the stateful session bean from the same browser, it is initialized and a new value of i is used. It has become so confusing for me.

Please guide.
 
Message for you sir! I think it is a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic