Book Image

EJB 3 Developer Guide

By : Michael Sikora
Book Image

EJB 3 Developer Guide

By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
Annotations and Their Corresponding Packages

Stateless Session Beans


A stateless session bean's state spans a single method call. We cannot have method A updating an instance variable x say, and expect the updated value of x to be available for any subsequent method invocation. This holds true both for a new method B which accesses x, or indeed, if method A is invoked a second or subsequent time. We have no guarantee that the same stateless session bean instance will be invoked between method calls. For this reason, stateless session beans should not use instance variables to maintain conversational state.

As a simple example we will develop a stateless session bean which simply returns the current time to the client. This is almost as minimal as the traditional HelloWorld example but is more useful. Recall a session bean component consists of a bean interface and a bean class. We name our interface TimeService.java, which contains a single method definition getTime() :

package ejb30.session;
import javax.ejb.Remote;
@Remote
public...