• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

stateless and stateful session beans

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
sujatha mamidala
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot sandy & saravan.
Suja.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic