• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Rules for the Bean class

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I am preparing for the SCBCD exam.. i have read both in the specs and in the HFE book that u should not have a finalize() method in your class.. Can anybody tell me why exactly this restriction is in place..

TIA
Krish
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where in spec? in which class?

Severin
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Generally, you put clean-up code to clean up non-memory related resources in the finalize() method so that when the object is about to be garbage collected, those resources are gracefully released. Examples for non-memory related resources include File, Socket, etc.

In case of EJBs, the life-time of a bean instance is controlled by the container. i.e, the container decides when to instantiate, activate, passivate, remove and associate an instance to EJBObject (to client). So you cannot rely on the code that you may put in the finalize() method. In other words, you may want the finalizer to run when a bean is no longer needed by a client .i.e, the client has invoked remove(), but the container may move the instance back to pool, in which case the finalizer will not be run.

OK. How do we discard an instance in Java?

In plain Java , we assign someObject = null. The object now becomes eligible for GC, finalizer runs and the instance is killed and memory is recovered.

But in EJB world, assigning null doesn't simply work. The client must invoke the remove() method on the remote object, so that the container can free the instance. But this does not mean that the bean instance associate with the EJBobject will be GCed. The container may move the instance back to pool. So there is no guarantee that finalizer will be run when an EJB instance is discarded (removed) by a client.
 
Krishnan Y N
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Keerthi,

Thx for the reply.. understood why finalize should be be present...

Cheerz
krish
 
Krishnan Y N
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Sorry for the typo, i wanted to say "understood why finalize() should not be there".

So in case we see a Bean Class with a finalize() method would that be treated as a class that is not obeying the EJB spec ?

Cheerz
krish
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic