aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Stateless vs Stateful Session Beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Stateless vs Stateful Session Beans" Watch "Stateless vs Stateful Session Beans" New topic
Author

Stateless vs Stateful Session Beans

Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 160

Hi Guys

I wanted to try and illustrate the difference between the two types of beans for myself, so I created a couple of classes and remote interfaces as follows:


I then exposed the call() methods through a web service and invoked each of them four times. My output (in the Glassfish log) was as follows:

INFO: Stateless bean: 1
INFO: Stateful bean: 1
INFO: Stateless bean: 2
INFO: Stateful bean: 2
INFO: Stateless bean: 3
INFO: Stateful bean: 3
INFO: Stateless bean: 4
INFO: Stateful bean: 4


I was expecting the stateful bean's counter to be incremented with each call, but I didn't expect the stateless bean to do the same - I thought that it would essentially lose track of whatever state it was in (i.e. that it would be lost after being invoked, and that the next call would get a new instance). What am I missing?

Cheers,
Riaan


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 160

Anyone?
Ragavan Natarajan
Greenhorn

Joined: Apr 09, 2012
Posts: 1
This might help you.

http://www.coderanch.com/t/312022/EJB-JEE/java/Stateless-Session-Bean-maintain-state
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 160


Thank you Ragavan, and welcome to JavaRanch!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stateless vs Stateful Session Beans