Getting Started with Enterprise JavaBeans™

G

Session Beans

Tutorial Home Section Home Previous Next

Get

Get

Stateless Session Beans

     Stateless session beans do not maintain conversational state with any given client for longer than the duration of a specific method invocation. From the client perspective, then, a stateless session bean may be seen as a group of methods that use only local variables and remember nothing from previous client interaction. In addition, the container may choose to serve the same instance of a stateless session bean to multiple clients or use different bean instances at different times to service one client's requests: the container sees every instance of a specific session bean type as equivalent. One implication of the way stateless session beans work is that there can only be a single ejbCreate() method, with no arguments. A container may choose to passivate (put to secondary storage) a stateful session bean, but never does so with stateless session beans. Because of these characteristics, stateless session beans can offer greater scalability and performance than most other types of beans.

     There are only two milestones in a stateless session bean's life cycle: Does Not Exist and Ready. A container may maintain a method-ready pool, which is a pool of active, ready to serve beans. To place a session bean in the Ready state, the container:

     When the container no longer requires the bean, it calls the ejbRemove() method so the bean can perform any necessary cleanup prior to termination. After this action, the bean is effectively destroyed and back to the Does Not Exist state.

     Note that there is not necessarily any correlation in time between a client's create() and remove() calls and a container's ejbCreate() and ejbRemove() calls. Also, the bean class must have a public, no argument constructor to accommodate the container's Class.newInstance() invocations.

     It is important to understand that stateless session beans can maintain state (that is, use instance variables) for data and references that apply to bean functionality, or to all clients as opposed to a specific client. For example, references to database connections, message queues, or email servers might be maintained. Just keep in mind that, once a method returns, there is no reliable state in the bean for a given client.



Tutorial Home Section Home Previous Next