1 Answer(s)      6 years and 11 months ago
Posted in : Java Interview Questions
View Answers

December 3, 2008 at 11:05 PM

Hi friend,

# Stateless Session Beans:

A stateless session bean does not maintain a conversational state with the client.
When a client invokes the methods of a stateless bean, the instance of bean variables may
contain a state specific to that client only for the duration of a method invocation.
Once the method is finished, the client-specific state should not be retained i.e. the EJB container
destroys a stateless session bean.
These types of session beans do not use the class variables (instance variables).
So they do not persist data across method invocation and therefore there is no need to passivates the bean's instance.
Because stateless session beans can support multiple clients, they provide the better scalability for
applications that require large numbers of clients.

# Stateful Session Beans:

These types of beans use the instance variables that allows the data persistent
across method invocation because the instance variables allow persistence of data across method invocation.
The client sets the data to these variables which he wants to persist. A stateful session bean retains its state
across multiple method invocations made by the same client. If the stateful session bean's state is changed during a method invocation,
then that state will be available to the same client on the following invocation. The state of a client bean is retained
for the duration of the client-bean session. Once the client removes the bean or terminates, the session ends and the state disappears.
Because the client interacts with its bean, this state is often called the conversational state.

When to use session beans:

Generally session beans are used in the following circumstances:

* When there is only one client is accessing the beans instance at a given time.
* When the bean is not persistent that means the bean is going to exist no longer.
* The bean is implementing the web services.

Stateful session beans are useful in the following circumstances:

* What the bean wants to holds information about the client across method invocation.
* When the bean works as the mediator between the client and the other component of the application.
* When the bean have to manage the work flow of several other enterprise beans.

Stateless session beans are appropriate in the circumstances illustrated below:

* If the bean does not contain the data for a specific client.
* If there is only one method invocation among all the clients to perform the generic task.

Some points to be remmber for the difference between Stateful session bean and Stateless session bean

a) Stateful beans are also Persistent session beans. They are designed to service business processes
that span multiple method requests or transactions.

Stateless beans are designed to service business process that last only for a single method call or request.

b) Stateful session beans remembers the previous requests and reponses.
Stateless session beans do not remember the previous request and responses.

c)Stateful session beans does not have pooling concept.
Stattless session bean instances are pooled.

d) Stateful S.Beans can retain their state on behave of an individual client.
Stateless S.Beans donot maintain states.

e) Stateful S.Beans can be passivated and reuses them for many clients.
Stateless S.Beans, client specific data has to be pushed to the bean for each method invocation which
result in increase of network traffic.

f)Stateful session beans have the passivated and Active state which the Stateless bean does not have.

g)Stateless Session beans are scaleable and can therefore be
replaced by an enhanced model whereas Stateful Session beans are not scaleable.

h)ejbActivate() and ejbPassivate() methods are not called in Stateless session beans

For more information on EJB visit to :




Related Tutorials/Questions & Answers:
ejb  what is ejb   ejb is entity java bean
ejb  why ejb components are invisible components.justify that ejb components are invisible
EJB  How is EJB different from servlets
Ejb  what kind of web projects requires ejb framework
Ejb  what kind of web projects requires ejb framework
Ejb  what kind of web projects requires ejb framework
ejb  what is the best book to study ejb with examples in weblogic with (netbeans or eclipse)   Please visit the following link: http://www.roseindia.net/javabeans/javabeans.shtml
ejb - EJB
ejb  how can i run a simple ejb hello application.please give me...: http://roseindia.net/ejb/ejbtutorial/building_a_simple_ejb_application.shtml http://www.roseindia.net/ejb/ejb-hello-world.shtml Hope
ejb - EJB
://www.roseindia.net/ejb/ Thanks
to : http://www.roseindia.net/ejb/SessionBean.shtml Thanks
EJB-MDB  What are the MDB transaction attributes
java EJB - EJB
Types of EJB? - EJB
Types of EJB?  Explain different types of EJB and how it will be differ from one to another?  Hi friend, Read for more information. http://www.roseindia.net/ejb
ejb vs hibernate - EJB
EJB in jsp code - EJB
EJB in jsp code  Suppose in EJB we created the session bean, remote... can we access the EJB methods in the jsp file.... if u can present me... the following links: http://www.roseindia.net/ejb/examples-of-StatelessBean.shtml
how to call ejb with in another ejb - EJB
how to call ejb with in another ejb  Does any one have idea about ...how to call ejb with in another ejb
Design patterns in ejb - EJB
EJB Environment
EJB Environment  can we work EJB in JDK1.4
EJB communication - EJB
EJB Example - EJB
EJB Example  Hi, My Question is about enterprise java beans, is EJB stateful session bean work as web service? if yes can you please explain... the following link: http://www.roseindia.net/ejb/WebServices.shtml Hope
java - EJB
java  execution process of ejb