Movatterモバイル変換


[0]ホーム

URL:


Document Information

Preface

Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

4.  Java Servlet Technology

5.  JavaServer Pages Technology

6.  JavaServer Pages Documents

7.  JavaServer Pages Standard Tag Library

8.  Custom Tags in JSP Pages

9.  Scripting in JSP Pages

10.  JavaServer Faces Technology

11.  Using JavaServer Faces Technology in JSP Pages

12.  Developing with JavaServer Faces Technology

13.  Creating Custom UI Components

14.  Configuring JavaServer Faces Applications

15.  Internationalizing and Localizing Web Applications

Part III Web Services

16.  Building Web Services with JAX-WS

17.  Binding between XML Schema and Java Classes

18.  Streaming API for XML

19.  SOAP with Attachments API for Java

Part IV Enterprise Beans

20.  Enterprise Beans

What Is an Enterprise Bean?

Benefits of Enterprise Beans

When to Use Enterprise Beans

Types of Enterprise Beans

What Is a Session Bean?

State Management Modes

Stateful Session Beans

Stateless Session Beans

When to Use Session Beans

What Is a Message-Driven Bean?

What Makes Message-Driven Beans Different from Session Beans?

When to Use Message-Driven Beans

Defining Client Access with Interfaces

Remote Clients

Local Clients

Deciding on Remote or Local Access

Web Service Clients

Method Parameters and Access

Isolation

Granularity of Accessed Data

The Contents of an Enterprise Bean

Naming Conventions for Enterprise Beans

The Life Cycles of Enterprise Beans

The Life Cycle of a Stateful Session Bean

The Life Cycle of a Stateless Session Bean

The Life Cycle of a Message-Driven Bean

Further Information about Enterprise Beans

21.  Getting Started with Enterprise Beans

22.  Session Bean Examples

23.  A Message-Driven Bean Example

Part V Persistence

24.  Introduction to the Java Persistence API

25.  Persistence in the Web Tier

26.  Persistence in the EJB Tier

27.  The Java Persistence Query Language

Part VI Services

28.  Introduction to Security in the Java EE Platform

29.  Securing Java EE Applications

30.  Securing Web Applications

31.  The Java Message Service API

32.  Java EE Examples Using the JMS API

33.  Transactions

34.  Resource Connections

35.  Connector Architecture

Part VII Case Studies

36.  The Coffee Break Application

37.  The Duke's Bank Application

Part VIII Appendixes

A.  Java Encoding Schemes

B.  About the Authors

Index

 

The Java EE 5 Tutorial

Java Coffee Cup logo
PreviousContentsNext

What Is a Session Bean?

Asession bean represents a single client inside the Application Server. To access anapplication that is deployed on the server, the client invokes the session bean’smethods. The session bean performs work for its client, shielding the client fromcomplexity by executing business tasks inside the server.

As its name suggests, a session bean is similar to an interactive session.A session bean is not shared; it can have only one client, inthe same way that an interactive session can have only one user. Likean interactive session, a session bean is not persistent. (That is, its datais not saved to a database.) When the client terminates, its session beanappears to terminate and is no longer associated with the client.

For code samples, seeChapter 22, Session Bean Examples.

State Management Modes

There are two types of session beans: stateful and stateless.

Stateful Session Beans

The state of an object consists of the values of its instance variables.In astateful session bean, the instance variables represent the state of aunique client-bean session. Because the client interacts (“talks”) with its bean, this stateis often called the conversational state.

The state is retained for the duration of the client-bean session. If theclient removes the bean or terminates, the session ends and the state disappears.This transient nature of the state is not a problem, however, because whenthe conversation between the client and the bean ends there is no needto retain the state.

Stateless Session Beans

Astateless session bean does not maintain a conversational state with the client.When a client invokes the methods of a stateless bean, the bean’s instancevariables may contain a state specific to that client, but only for theduration of the invocation. When the method is finished, the client-specific state shouldnot be retained. Clients may, however, change the state of instance variables inpooled stateless beans, and this state is held over to the next invocationof the pooled stateless bean. Except during method invocation, all instances of astateless bean are equivalent, allowing the EJB container to assign an instance toany client. That is, the state of a stateless session bean should applyaccross all clients.

Because stateless session beans can support multiple clients, they can offer better scalabilityfor applications that require large numbers of clients. Typically, an application requires fewerstateless session beans than stateful session beans to support the same number ofclients.

A stateless session bean can implement a web service, but other types ofenterprise beans cannot.

When to Use Session Beans

In general, you should use a session bean if the following circumstances hold:

  • At any given time, only one client has access to the bean instance.

  • The state of the bean is not persistent, existing only for a short period (perhaps a few hours).

  • The bean implements a web service.

Stateful session beans are appropriate if any of the following conditions are true:

  • The bean’s state represents the interaction between the bean and a specific client.

  • The bean needs to hold information about the client across method invocations.

  • The bean mediates between the client and the other components of the application, presenting a simplified view to the client.

  • Behind the scenes, the bean manages the work flow of several enterprise beans. For an example, see theAccountControllerBean session bean inChapter 37, The Duke's Bank Application.

To improve performance, you might choose a stateless session bean if it hasany of these traits:

  • The bean’s state has no data for a specific client.

  • In a single method invocation, the bean performs a generic task for all clients. For example, you might use a stateless session bean to send an email that confirms an online order.

PreviousContentsNext

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices


[8]ページ先頭

©2009-2025 Movatter.jp