This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Stateless Session Bean and remove() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Stateless Session Bean and remove()" Watch "Stateless Session Bean and remove()" New topic
Author

Stateless Session Bean and remove()

Shreyas Reddy
Ranch Hand

Joined: Oct 09, 2003
Posts: 49
If a stateless session bean doesn't really care when remove() is called, and as per page 282 of HFE nothing happens to the bean when client calls remove(), how come an exception is thrown if the client tries to use the EJB reference after removing the bean? Isn't removing the bean same as calling remove on the bean?

I have a home ref
I call create on home ref
I call bus method on component interface
then i call remove --> nothing really happens
i call bus method on component interface --> does this throw an exception?
thx,
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Ahhh... this is a good question.

When the client calls remove() on a stateless bean (or remove(Handle) on the remote home interface for a stateless ean), the Container doesn't care from the bean object's perspective... in other words, the Container isn't going to kill the bean simply because the client said to remove it.
(As opposed to with StateFUL beans where the Container WILL kill the bean as a result of the client saying remove(), since that stateful bean has no meaningful life except for with that one client).

But... the Container DOES acknowledge that the CLIENT is done with that bean. So the Container keeps the bean alive, and the bean never even knows that any of the client's it has serviced are done with it, but the Container still knows which clients have said they were done.

In other words, when the client calls remove() on a stateFUL bean, the client says, "Kill the bean and I am done with it forever." When the client calls remove() on a stateLESS bean, the client says, "I am done with the bean forever". So the Container knows that this client has already said that he is done with the bean, and any attempt by that client to use that bean again means something is wrong with the logic of that client, so the Container complains.

And if the Container had been keeping any resources available for that client, those resources go away.

cheers,
Kathy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stateless Session Bean and remove()