EnterpriseBean and finalize()

Discussion in 'Java' started by Jono, Sep 2, 2006.

  1. Jono

    Jono Guest

    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
     
    Jono, Sep 2, 2006
    #1
    1. Advertising

  2. Jono

    Adam Maass Guest

    "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
     
    Adam Maass, Sep 2, 2006
    #2
    1. Advertising

  3. 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
     
    =?windows-1252?Q?Arne_Vajh=F8j?=, Sep 2, 2006
    #3
  4. Jono

    Jono Guest

    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
     
    Jono, Sep 3, 2006
    #4
  5. 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
     
    =?windows-1252?Q?Arne_Vajh=F8j?=, Sep 4, 2006
    #5
  6. Jono

    Jono Guest

    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
     
    Jono, Sep 4, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul J. Lucas
    Replies:
    14
    Views:
    759
    Mike Schilling
    Aug 24, 2005
  2. Stofdeel

    Deconstructor and finalize

    Stofdeel, May 17, 2006, in forum: Java
    Replies:
    8
    Views:
    7,767
    Stofdeel
    May 17, 2006
  3. Nainto
    Replies:
    0
    Views:
    263
    Nainto
    May 3, 2006
  4. andrey
    Replies:
    0
    Views:
    164
    andrey
    Dec 15, 2007
  5. Andrey Nikitin
    Replies:
    1
    Views:
    173
    Nobuyoshi Nakada
    Dec 16, 2007
Loading...

Share This Page