• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finalize() method in the bean class  RSS feed

 
Karen Young
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I've been reading up on EJB technology and the book says a bean class cannot define the finalize() method. Why? Can I define the finalize() method if I have a finally{} block in there that calls super.finalize()? Thank you.
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

finalize() should not be declared as it may or may not be invoked.

When a bean is removed from instance pool , its unsetEntityContext() is invoked- this method let the bean release any resources it helds before this bean instance is garbage collected. finalize() may or may not be invoked because it depends on each EJB vendor's own implementation about the way of destroying the bean instance.
 
Karen Young
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, does that mean the compiler will not allow an empty finalize() method? Or is it just good practice not to hane a finalize method? Thank you.
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never tried using finalize() in bean so don't know if compiler rejects it or not. Moreover the way I read in EJBbook, it specifies that finalize() implementation is vendor specific. It depends on EJB container/server that you are using and in general its a good practice not to have this method in Bean.
 
Zak Nixon
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would discourage using finalize() for anything.

Zak
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!