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.
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