Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

EnterpriseBean and finalize()

Thread view: 
Jono - 02 Sep 2006 10:05 GMT
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 - 02 Sep 2006 12:44 GMT
> Hi Everyone,
> I'm trying to learn EJB and picked up a copy of the book "SCBCD Exam
[quoted text clipped - 12 lines]
> 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øj - 02 Sep 2006 22:13 GMT
> 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
[quoted text clipped - 8 lines]
> 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 - 03 Sep 2006 08:39 GMT
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

> > 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
[quoted text clipped - 32 lines]
>
> Arne
Arne Vajhøj - 04 Sep 2006 01:31 GMT
> 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
[quoted text clipped - 4 lines]
> 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 - 04 Sep 2006 08:42 GMT
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

> > 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
[quoted text clipped - 13 lines]
>
> Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.