Complaints about bean removal

Implementing ejbRemove()
ejbRemove()
Release any resources, or do whatever clean-up you need to do before the bean dies forever. Much of the time, your ejbRemove() method will be empty, because if your bean does use resources, it most likely will acquire and release the resources in each business method. But if your design does call for keeping resources open throughout the bean’s life, then you need to free them up here!

an alternative...
Call a cleanUp() method from both ejbPassivate() and ejbRemove(). Given that your bean could be removed without an ejbRemove() call, if it times out while passivated, you should have both your ejbPassivate() and ejbRemove() methods perform the same clean-up. Since scarce system resources are seldom Serializable anyway, you’re probably already taking care of them in ejbPassivate().
public void ejbRemove() {
this.cleanUp();
}
public void ejbPassivate() {
this.cleanUp();
}
private void cleanUp() {
try {
myResource.close();
} catch(Exception ex) {...}
}Note
now both ejbRemove() and ejbPassivate() will do the same thing, so even if you time out while passivated, you don’t have to worry.
Missed ejbRemove() calls

Watch it!
You must be ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access