Search code examples
javajakarta-eeejbjmsjava-ee-6

finalize method in MessageDrivenBean


Message-Driven Bean Class

the requirements of a message-driven bean class:

It must not define the finalize method.

What is the reason for above requirement ?


Solution

  • If you look in the EJB spec, you will see that it is a requirement for all types of EJB.

    http://download.oracle.com/otndocs/jcp/ejb-3.1-pfd-oth-JSpec/

    I can't find a definitive answer but looking on various Java forums over the last 13 years, you can see answers consistently saying that, because the container will decide the life-cycle of the EJB, the finalize may never be called (or called when you don't expect) and it would there be dangerous to use it.

    https://community.oracle.com/thread/1582366