wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes Problem in understanding session beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem in understanding session beans" Watch "Problem in understanding session beans" New topic
Author

Problem in understanding session beans

Poornima Sharma
Ranch Hand

Joined: Sep 09, 2008
Posts: 114
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.


Poornima Sharma
SCJP 6.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in understanding session beans
 
Similar Threads
Session Beans and SessionBean interface.
ClassCastException for Stateful Bean in JBoss
ETS Question doubts
Multiple postconstruct and predestroy methods.
@ExcludeClassInterceptors annotation