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 remove in stateless session beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "remove in stateless session beans" Watch "remove in stateless session beans" New topic
Author

remove in stateless session beans

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1088
    
  10

Hello,
I deploy a stateless session beans and then call remove() on the remoteObject. But, the ejbRemove() is never called on a stateless session bean. Shouldn't the container call the ejbRemove() when I invoke remove?

Thank You,
Ranga.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Shreyas Reddy
Ranch Hand

Joined: Oct 09, 2003
Posts: 49
As per my understanding, when a client calls remove on a Stateless SB, the client is just indicating that she/he is done witht he bean and will not be able to use the EJB Object reference anymore. The container throws an exception if you try to use the reference once you call remove.
The container does not remove the bean and does not call ejbRemove when the client calls remove. The container removes the bean whenever it likes depending on its implementation.

To answer ur question simply, the ejbRemove is not called when client calls remove for a stateless session bean.
Frederic Filiatrault
Ranch Hand

Joined: Jul 12, 2004
Posts: 69
Exactly, it is vendor specific. Some will call ejbRemove, it depends, best way to find out is to check yourself.

For exam purposes, don't rely on ejbRemove. Never.

Hope this helps !


F.<br />SCJP, SCJD, SCWCD, SCBCD<br /> <br />Failure is not an option... It comes with the software bundle.
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
Originally posted by Frederic Filiatrault:

For exam purposes, don't rely on ejbRemove. Never.


What does this mean?
Regards,
Leena


[SCJP2, SCWCD1.3, SCBCD]
Naslai Shobha
Greenhorn

Joined: Aug 18, 2004
Posts: 12
Hi Ranganathan,

For the stateless session ejbs, when the client calls create() only the remote stub gets created and is returned to the client.

The remote stub gets associated with the SLSB in the pool, when a business method is invoked.

Hence when the create() is actually not creating the bean, its the same case with remove() also. Only the remote stub is invalid after a remove method. The bean instance still lies in the pool.

Hope this helps.

Shobha Naslai
SCJP, SCWCD
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1088
    
  10

Thanks for your replies.

1.But the reason I raised this question is because, let's say I establish a database connection in ejbCreate. So, now in ejbRemove() I have written a code that will disconnect to the database. So, though the client says that he has finished using the bean, the container won't still call ejbRemove(), which means the databse connection stays.

And if I am going to connect and disconnect in business method itself it would be very slow.

2.If it varies from container to container, what does the spec say about this?

Thanks,
Ranga.
Shreyas Reddy
Ranch Hand

Joined: Oct 09, 2003
Posts: 49
SLSB dies(does not exist anymore) at the Container's will or when the bean throws a system(unchecked/uncaught) exception.If the bean is removed by the container beacuse the pool size is too big or some other reason then ejbRemove() is called by the container before the bean dies. If the bean dies because of a system exception then ejbRemove() is not called and the system resources are not freed.
As you said, ejbCreate and ejbRemove are the places to connect and disconnect to DB.
Someone answer this --If a system exception is thrown, how do we free the resources?
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
If you want you bean to be scalable, you won't open a connection in ejbCreate. What happens if you have 100 beans in the pool? You would end up with 100 open database connections. The best way is to lookup the DataSource during ejbCreate and then use it to get a connection only when you need it within a business method and close it when you are done with it.

The database connection is not actually opened and closed if you do this, so getting the connection should not be that much overhead. At least not compared to the overhead of maintaining all those database connections.
Sekhar Kadiyala
Ranch Hand

Joined: Feb 17, 2004
Posts: 170
Thats was a good point. Also as per the specifications, we can't depend on the remove() method either for stateless or stateful session beans. Developers have to ensure system still releases all resources evebn without getting to remove methods.


PMP CSQA SCJP SCWCD SCBCD INS 21 INS 23
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: remove in stateless session beans