File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in understanding session beans

 
Poornima Sharma
Ranch Hand
Posts: 114
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic