• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why can't one define the finalize method for EJBs?

 
Walter Chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see that because the lifecycles of EJBs are managed by the EJB container and there are lifecycle methods such as ejbCreate and ejbRemove there is no need for the finalize method, but what is the official explanation?
Thanks,
Walter
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the restriction on finalize() is to discourage (or in this case forbid) people from using it to cleanup resources since it is not managed by the Container. Those types of resources should be managed in the appropriate lifecycle method (ejbRemove() for Session and Message Driven Beans, unsetEntityContext() for Entity Beans).
In a similar fashion, explicitly defining a no-args constructor for your EJBs is discouraged (but not actually forbidden by the spec). Any initialization code should really be placed into the appropriate lifecycle method.
These restrictions give the Container make flexibility when it comes to instance pooling.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!