"Jono" <> wrote:
> Hi Everyone,
> I'm trying to learn EJB and picked up a copy of the book "SCBCD Exam
> Study Kit" by Paul Sanghera. Inside it, I came across the following
> sentence, which piqued my interest because I cannot see a) where this
> can be found in the EJB 2.0 specification (actually, I was looking in
> the J2EE 1.3 specification), or b) why finalizing a bean would be
> interfering with the responsibilities of the container. Here's the
> quote:
>
> "... the bean class must not have any finalize() method because by
> doing this you would be stepping on the container's toes, since it is
> the responsibility of the container to manage the lifecycle, threads,
> garbage collection, and so forth."
>
> If anyone can shed a little light on this, and dispel the confusion,
> I'd really appreciate it.
>
Certainly, entity bean instances may be pooled. If those instances have
'finalize' methods, then it would be invoked at some potentially very
inconvenient times for the container, and almost certainly much later than
the programmer intended. On the other hand, there are certain events that
can cause an instance to expelled from the pool, and the 'finalize' method
would eventually be called on the instance (much sooner than the programmer
intended). Programming with beans means letting the container do a lot of
the work. A 'finalize' method interferes with work that the container is
supposed to be doing for you.
-- Adam Maass
|