EnterpriseBean and finalize()

J

Jono

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
 
A

Adam Maass

Jono said:
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
 
?

=?windows-1252?Q?Arne_Vajh=F8j?=

Jono said:
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
 
J

Jono

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
 
?

=?windows-1252?Q?Arne_Vajh=F8j?=

Jono said:
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
 
J

Jono

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
 

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top