Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Stateless Session Bean and remove()

Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Cowgirl and Author
Posts: 1589
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Normally trees don't drive trucks. Does this tiny ad have a license?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic