uCosminexus Application Server, EJB Container Functionality Guide

[Contents][Glossary][Index][Back][Next]

4.3.1 Precautions during the implementation of a Stateless Session Bean

This subsection describes the precautions to be taken when implementing a Stateless Session Bean.

Organization of this subsection
(1) Releasing the references with the remove method
(2) About accessing the resource manager with the ejbCreate method and with a method in which the @PostConstruct annotation is specified
(3) Precautions about sharing of Bean classes
(4) About invoking the begin method of javax.transaction.UserTransaction either with the ejbRemove method or with a method in which the @PreDestroy annotation is specified

(1) Releasing the references with the remove method

When you invoke a Stateless Session Bean using the home interface, you acquire the references by invoking the create method of the home interface. However, when the invocation of the Session Bean is complete, you must release the references by invoking the remove method. If you do not release the references, the memory on the J2EE server will remain occupied.

Furthermore, by specifying the option that makes the invocation of the remove method unnecessary, the invocation of the remove method for the EJB objects of the Stateless Session Bean will become unnecessary. If you enable this option, you can invoke the business method after invoking the remove method.

If this option is disabled, you must invoke the remove method. Furthermore, when you invoke the business method after invoking the remove method, the java.rmi.NoSuchObjectException exception will be returned to the invocation source.

In the ejbserver.rmi.stateless.unique_id.enabled key of usrconf.properties, you specify the option that makes the invocation of the remove method unnecessary and define the option for the J2EE servers. For details on the key, see 2.4 usrconf.properties (User property file for J2EE servers) in the uCosminexus Application Server Definition Reference Guide.

(2) About accessing the resource manager with the ejbCreate method and with a method in which the @PostConstruct annotation is specified

According to the EJB specifications, accessing the resource manager with the ejbCreate method or with a method in which the @PostConstruct annotation is specified is not allowed.

(3) Precautions about sharing of Bean classes

Do not use the same Session Bean as a Stateful Session Bean and Stateless Session Bean in the same J2EE application.

(4) About invoking the begin method of javax.transaction.UserTransaction either with the ejbRemove method or with a method in which the @PreDestroy annotation is specified

The begin method of javax.transaction.UserTransaction might be invoked either with the ejbRemove method of the Stateless Session Bean or with a method in which the @PreDestroy annotation is specified. However, according to the EJB specifications, you cannot use this method after invocation. Do not invoke the begin method of javax.transaction.UserTransaction.