Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > EnterpriseBean and finalize()

Reply
Thread Tools

EnterpriseBean and finalize()

 
 
Jono
Guest
Posts: n/a
 
      09-02-2006
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

 
Reply With Quote
 
 
 
 
Adam Maass
Guest
Posts: n/a
 
      09-02-2006

"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


 
Reply With Quote
 
 
 
 
=?windows-1252?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      09-02-2006
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
 
Reply With Quote
 
Jono
Guest
Posts: n/a
 
      09-03-2006
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øj 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


 
Reply With Quote
 
=?windows-1252?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      09-04-2006
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
 
Reply With Quote
 
Jono
Guest
Posts: n/a
 
      09-04-2006
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øj 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57