Java Reference
In-Depth Information
as we go along. For now, be aware that the container will start, stop, instantiate,
destroy, and provide network services to the EJBs it contains.
21.2.2
Enterprise JavaBeans come in more than one variety. Let's take a look at those.
Bean Types
21.2.2.1
A session bean is a reusable component that represents a collection of server
methods. The intention is that each such method represents some business
process, such as addCustomer() , createShoppingCart() , and so on.
Session beans are thus organized around business processes. Actually, a
session bean is not much more than a facade that collects a business process
API into a single class. But remember what EJBs give you—networked server-
based functionality, load balancing, clustering features, reliability, failover, and
the ability to handle increased demand by merely adding more Bean instances
and server hardware. The power comes not from how EJBs extend the language,
but from how they automate and hide infrastructure.
Session beans come in two major varieties: stateless and stateful. Let's take
a look at what they offer and the differences between the two.
Session Beans
Stateless Session Beans
What they are. A stateless session bean is one where each method call is
completely independent of any other method call, whether by one or many
clients.
An EJB application designed this way has certain advantages. Since a single
Bean instance can be switched from client to client on demand (because no
state information is kept between method invocations), a small number of Bean
instances can handle a large number of clients. Compare this with stateful
session beans described below.
Why you would use them. In a sense, this is the optimum bean. If you can
design your application to use nothing but stateless session beans (perhaps
backed by entity beans), then you have a maximally flexible, extensible, and
adaptable enterprise application—one that can be easily scaled from a single
application server to a very large cluster. Why? Because the lack of state infor-
mation means that any single Bean instance can serve any given client at any
Search WWH ::




Custom Search