File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes stateless and stateful session beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "stateless and stateful session beans" Watch "stateless and stateful session beans" New topic
Author

stateless and stateful session beans

sujatha mamidala
Greenhorn

Joined: Nov 20, 2000
Posts: 19
Could somebody please explain me the diff between those two in detail with one small ex. I would really appreciate it.
Thanks A Lot,
Suja.
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
Stateless as the name suggests do not store the user/any other information. So they are used only as business logic minus the user information mechanisms. Can be used where u wanna do some processing irrespective of which user is using the bean. They are used generally as one per many clients. Stateful session beans are beans that keep the user/other info. i.e. they maintain the state information. Like in a typical shopping cart where u have to keep a track of which user does what. They are normally one per user and their state is written to a temporary store in case more than 1 users use the same StatefulSB and the container automatically switches context depending on which user has the current handle to the bean.
HTH
Sahil


Adios
Saran Vel
Ranch Hand

Joined: Nov 03, 2000
Posts: 111
Hi,
Stateful session beans maintain conversational state when used by client.
Conversational state means, the beans state is kept in memory while a client uses a session (but it is not written to a database though).
Maintaining conversational state allows a client to carry on a conversation with a bean. As each method on a bean is invoked, the state of the session bean may change, and the change can affect subsequent method calls. So for the subsequent method calls the client will get the updated state of the bean.
Conversational state is kept for as long as the client application is actively using the bean. Once the client shuts down or releases the bean, the convesational state is lost forever.
Stateful session beans are not shared among clients, but they r dedicated to the same client for the life of the bean.
On the other hand stateless session bean do not maintain any conversational state. Each method is completely independent and uses only data passed in its parameters.
So stateless session beans r shared among the clients and a single bean instance can serve multiple clients.
Hope u get cleared to some extent.. for detailed explanation with example, refer Enterprise JavaBeans by oreilly publications..
Saran


Saran
Sun Certified Java2 Programmer
sujatha mamidala
Greenhorn

Joined: Nov 20, 2000
Posts: 19
Thanks a lot sandy & saravan.
Suja.
schennamaraja
Greenhorn

Joined: Mar 06, 2001
Posts: 2

Refer to Ed Roman's Book "Mastering EnterPrise Java Beans", you can down load the pdf version for free from ServerSide.com. He explains it very well...
suzi lu
Greenhorn

Joined: Jan 05, 2001
Posts: 17
I just want to know how stateless session beans store the state...i mean what is the mechanism used to store the state...
Tx,
Suzi
Madhu Juneja
Ranch Hand

Joined: Mar 10, 2001
Posts: 176
The mechanism used to store the state...
You just need to pass the parameters you want to be stored in the conversational state through the ejbCreate method(s) of the stateless bean.
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
suzi,
stateless beans generally do not store the state, only stateful do .... in case u want that u'r stateless session beans shud store the state u have to write the state(variables) to a temporary storage before a context switching(new user taking over) occurs. Or else and better let tthe stateful beans do it as this is their job.
HTH
Sahil
suzi lu
Greenhorn

Joined: Jan 05, 2001
Posts: 17
Sorry, i meant the stateful session benas..i know that stareless session beans do not store the state........
I do know that we need to pass in parameters thru the create method, but i wnat to know the mechanism inside to store the state.
Tx,
Suzi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: stateless and stateful session beans