File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Stateless Session Bean and remove()
 
Similar Threads
calling remove a staless bean
RemoveException or EJBException
Stateless session bean test
EJB Notes I prepared during my preparation for SCBCD
Cleared SCBCD last week.. some notes