• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

remove in stateless session beans

 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Frederic Filiatrault:

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



What does this mean?
Regards,
Leena
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic