Quiz
|
Exercises
|
Day 11. Creating Stateless Session Beans
Yesterday, you
Today you will be looking at the other type of session EJB, the stateless session bean. You will be covering concepts such as the life cycle of stateless session beans, their components, and so on. Also, you will be converting the chef classes of the restaurant application from yesterday into a stateless session bean. In addition to this, you will be covering concepts about accessing a stateless session bean from a CORBA or RMI client. The final part of the day will be devoted to building the transactional
|
Life Cycle of a Stateless Session EJBThe life cycle of a stateless session bean varies from the life cycle of a stateful session bean.
Figure 11.1 shows that the life cycle of a stateless session bean is
Figure 11.1. Life cycle of a stateless session bean.
Creation
Similar to a stateful session bean, the stateless session bean is created by the EJB container as a new instance of the stateless session bean after the client application invokes the
create()
method on the home interface of the stateless session bean. As a part of the creation process, the
setSessionContext()
method of the stateless session bean is invoked by the EJB container. The final step in the creation of a stateless session bean is the EJB container's invoking the
ejbCreate()
callback method on the bean instance. Because no state information about the client application is
The stateless session bean is now active and ready to process client application
Process Operations
Stateless session beans are transactional
TerminationA client application can terminate a stateless session bean by invoking the remove() method on the home interface of the stateless session bean. When the remove() method is invoked, the EJB container may either destroy the instance of the stateless session bean or return the instance to the stateless session bean pool. An EJB container can return the instance to the bean pool because no state information is communicated between the stateless session bean and the client application. This enables the EJB container to minimize the overhead associated with destroying a stateless session bean instance. The steps involved in developing stateless session beans are exactly the same as those described for stateful session beans. Hence, today's lesson will not go over the flowchart for developing a stateless session bean. The only differences between the two are that a stateless session bean contains only one ejbCreate() method without parameters in the bean implementation class and in the deployment descriptor file ejb-jar.xml and that the bean is registered as a stateless session bean to distinguish it from a stateful session bean. Now that you understand the life cycle of a stateless session bean and the steps involved in building a stateless session bean, you are ready to study the concepts of stateless session beans in detail. |