• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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
 
Ranch Hand
Posts: 2713
  • 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.
    Bookmark Topic Watch Topic
  • New Topic