What is Session Bean?
A session bean is a non-persistent object that implements some business logic
running on the server. One way to think of a session object is as a logical
extension of the client program that runs on the server.
Session beans are used to manage the interactions of entity and other session beans,access resources, and
generally perform tasks on behalf of the client.
There are two basic kinds of session bean: stateless and stateful.
Stateless session beans are made up of business methods that behave like
procedures; they operate only on the arguments passed to them when they are
invoked. Stateless beans are called stateless because they are transient; they
do not maintain business state between method invocations.Each
invocation of a stateless business method is
independent from previous invocations. Because stateless session beans are
stateless, they are easier for the EJB container to manage, so they tend to
process requests faster and use less resources.
Stateful session beans encapsulate business logic and
state specific to a client. Stateful beans are called
“stateful” because they do maintain business state
between method invocations, held in memory and not persistent. Unlike stateless
session beans, clients do not share stateful beans.
When a client creates a stateful bean, that bean
instance is dedicated to service only that client. This makes it possible to
maintain conversational state, which is business state that can be shared by
methods in the same stateful bean.
What are the different kinds of enterprise beans?
Stateless session bean- An instance of these non-persistent EJBs provides a
service without storing an interaction or conversation state between methods.
Any instance can be used for any client.
Stateful session bean- An instance of these
non-persistent EJBs maintains state across methods and transactions. Each
instance is associated with a particular client.
Entity bean- An instance of these persistent EJBs represents an object view of
the data, usually rows in a database. They have a primary key as a unique
identifier. Entity bean persistence can be either container-managed or
bean-managed.
Message-driven bean- An instance of these EJBs is integrated with the Java
Message Service (JMS) to provide the ability for message-driven beans to act as
a standard JMS message consumer and perform asynchronous processing between the
server and the JMS message producer.
What is an EJB Context?
EJBContext is an interface that is implemented by the
container, and it is also a part of the bean-container contract. Entity beans
use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext
objects provide the bean class with information about its container, the client
using the bean and the bean itself. They also provide other functions.
How can I call one EJB from
inside of another
EJB?
EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home
Interface of the other bean, then acquire an instance reference, and so forth.
What is the difference between Message Driven Beans and Stateless Session beans?
In several ways, the dynamic creation and allocation of message-driven bean
instances mimics the behavior of stateless session EJB instances, which exist
only for the duration of a particular method call. However, message-driven
beans are different from stateless session EJBs (and other types of EJBs) in
several significant ways: Message-driven beans process multiple JMS messages
asynchronously, rather than processing a serialized sequence of method calls.
Message-driven beans have no home or remote interface, and therefore cannot be
directly accessed by internal or external clients. Clients interact with
message-driven beans only indirectly, by sending a message to a JMS Queue or
Topic. Only the container directly interacts with a message-driven bean by
creating bean instances and passing JMS messages to those instances as
necessary. The Container maintains the entire lifecycle of a message-driven
bean; instances cannot be created or removed as a result of client requests or
other API calls.
What happens if remove( ) is never
invoked on a session
bean?
In case of a stateless session bean it may not matter if we call or not as in
both cases nothing is done. The number of beans in cache is managed by the
container. In case of stateful session bean, the bean
may be kept in cache till either the session times out, in which case the bean
is removed or when there is a requirement for memory in which case the data is
cached and the bean is sent to free pool.
No comments:
Post a Comment