Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger
  • Frits Walraven

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

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?
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.
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic