EnterpriseBean and finalize()  
Author Message
Jono





PostPosted: 2006-9-2 17:06:00 Top

java-programmer, EnterpriseBean and finalize() 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.

Many thanks,

Jono

 
Adam Maass





PostPosted: 2006-9-2 19:45:00 Top

java-programmer >> EnterpriseBean and finalize()
"Jono" <email***@***.com> 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


 
Arne Vajh鴍





PostPosted: 2006-9-3 5:14:00 Top

java-programmer >> EnterpriseBean and finalize() Jono wrote:
> 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."

The EJB 2.1 spec has:

7.11.2 Session Bean Class
...
?The class must not define the finalize() method.

so it is in the spec.

Next question is why. EJB's has a long list of restrictions
on what they are allowed to use. The general intention is
to make sure that EJB are so well behaving that they will
work in all application servers and will not exhibit
bad characteristics compared to expectations of
a business component.

I can not see any specific reason for this particular
restriction.

But I can not see any reason to have a finalize method
either. It does not make any sense in the context an
EJB is used.

Arne
 
 
Jono





PostPosted: 2006-9-3 15:40:00 Top

java-programmer >> EnterpriseBean and finalize() Thank you for your answers to both of my questions. I'm guessing that
the restriction wasn't a part of the 2.0 spec and as such is misleading
in a book written to help people pass the SCBCD exam, but I can imagine
how it might increase the stability of enterprise beans in more current
versions of the specification. It's a pity that Sun only offer
certification on such an old version of this EJB technology - it would
feel far more rewarding to know you were certified in the cutting edge
Java EE.

Jono

Arne Vajh鴍 wrote:
> Jono wrote:
> > 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."
>
> The EJB 2.1 spec has:
>
> 7.11.2 Session Bean Class
> ...
> ?The class must not define the finalize() method.
>
> so it is in the spec.
>
> Next question is why. EJB's has a long list of restrictions
> on what they are allowed to use. The general intention is
> to make sure that EJB are so well behaving that they will
> work in all application servers and will not exhibit
> bad characteristics compared to expectations of
> a business component.
>
> I can not see any specific reason for this particular
> restriction.
>
> But I can not see any reason to have a finalize method
> either. It does not make any sense in the context an
> EJB is used.
>
> Arne

 
 
Arne Vajh鴍





PostPosted: 2006-9-4 8:32:00 Top

java-programmer >> EnterpriseBean and finalize() Jono wrote:
> Thank you for your answers to both of my questions. I'm guessing that
> the restriction wasn't a part of the 2.0 spec and as such is misleading
> in a book written to help people pass the SCBCD exam, but I can imagine
> how it might increase the stability of enterprise beans in more current
> versions of the specification. It's a pity that Sun only offer
> certification on such an old version of this EJB technology - it would
> feel far more rewarding to know you were certified in the cutting edge
> Java EE.

The EJB 2.0 spec says exactly the same:

7.10.2 Session bean class
The following are the requirements for session bean class:
...
?The class must not define the finalize() method.

Arne
 
 
Jono





PostPosted: 2006-9-4 15:42:00 Top

java-programmer >> EnterpriseBean and finalize() Thanks for pointing that out, Arne. In my haste to wrap things up on
Friday, I had done a quick search for "finalize" in the wrong
specification.
Regards,
Jono

Arne Vajh鴍 wrote:
> Jono wrote:
> > Thank you for your answers to both of my questions. I'm guessing that
> > the restriction wasn't a part of the 2.0 spec and as such is misleading
> > in a book written to help people pass the SCBCD exam, but I can imagine
> > how it might increase the stability of enterprise beans in more current
> > versions of the specification. It's a pity that Sun only offer
> > certification on such an old version of this EJB technology - it would
> > feel far more rewarding to know you were certified in the cutting edge
> > Java EE.
>
> The EJB 2.0 spec says exactly the same:
>
> 7.10.2 Session bean class
> The following are the requirements for session bean class:
> ...
> ?The class must not define the finalize() method.
>
> Arne