[ Team LiB ] Previous Section Next Section

Chapter 21. Working with Session Beans

by Subramanian H Kovilmadam

IN THIS CHAPTER

Chapter 20, "Enterprise JavaBeans and WebLogic Server," introduced the various types of Enterprise Beans that you can use in your application. In this chapter, we look at Session Beans in detail. Session EJBs, or Session Beans, manage business processes or workflow that must be performed to achieve the required result. Workflow is the sequence of the steps that must be performed to get a job done. In an online booking application, an airline reservation processor may be modeled as a Session Bean, which performs the business function of booking a seat for the customer. Session Beans may use Entity Beans for accessing data to perform their business operations. They may also directly access the database to perform the same tasks.

There are two types of Session Beans, based on their life cycle within the container. They are

  • Stateless Session Beans

  • Stateful Session Beans

As the name suggests, Stateless Session Beans do not maintain state specific to clients. In other words, the client requests the bean to perform a task, the bean performs the job, returns, and gets ready to process the next request. That isn't to say that a Stateless Session Bean cannot hold any state at all. It can hold state, but any state maintained within a Stateless Session Bean is shared across all clients accessing that bean instance. Stateless Session Beans can and will be shared among different clients. The parameters to the methods themselves may be specific to the client that's calling the method, but the life span of those parameters is complete when the business method completes its processing.

On the other hand, Stateful Session Beans act as extensions of the client inside the application server. Whatever function these beans perform is specific to the client that created the bean. These beans hold client state, and are not shared across different client instances. Note that the state of a Stateful Session Bean is volatile; it isn't persisted, as in an Entity Bean. In other words, if there's a system failure, the state held by a bean instance is gone forever.

This chapter provides a comprehensive study of Session Beans in the context of WebLogic 8.1. We cover EJB Specification Version 2.0, which WebLogic 8.1 is compliant with.

NOTE

For a general overview of EJBs, refer to Chapter 20. Also see Chapter 22, "Working with Entity Beans," and Chapter 23, "Working with Message-Driven Beans," for in-depth studies of those types of EJBs.

This chapter assumes a working knowledge of RMI on the part of the reader. For more information about RMI, refer to Chapter 11, "Creating Distributed Applications with RMI."


    [ Team LiB ] Previous Section Next Section