This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Stateful v/s stateless session bean

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I would like to know when a stateless session bean is used and when a statelful session bean is used.Dont seem to understand.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In short for application or web servers, stateless is good, stateful is, um, a concern.
Stateless beans can accept a request, handle the request, send a result, and then forget all about the user. The bean is then ready to handle the next request on behalf of another user.
But sometimes you must keep some information for the life of the user's session. Authentication information and shopping carts are a couple obvious examples. Having the server keep any information on behalf of the user in memory can limit the number of simultaneous users.
There are many places to stuff such stuff:
In Java or COM objects in memory
In server "session" storage
In a cookie
In hidden fields on the HTML page
In an XML data island on the page
In JavaScript on the page
Encoded on the URL
In temporary session storage on a database
On the real database of record

I bet folks here can think of more than that.
Stateful Session Beans were invented to save the developer some effort. The container can manage the state for you. If using too much memory swap to some external storage, restore it when the next user request comes in, synchronize between clustered servers, etc. The container can implement new techniques over time without changing application code.
Well, that was typically long for me. Did it help?
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear u,
i would suggest a simple response for ur question.
imagine a bean class
class examplebean
{
void setx()
{ x=10;}
void getx()
{ y=x+20;}
}
in the above class if u call setx ()
method in ur client application the value of x would be 10.
again when u call getx() the value of y would be
y=10+20 =30.
ie the state of the class varible "X"( value of x is not lost for the second method) is retained between method calls.
whereas if u take a stateless session bean
class HelloBean
{ void sayHello()
{System.out.println("Hello World");
}
there are no state objects like varibles x whose state ( rather value) has to be retained between method calls.
Cordially urs,
Lalitha.S
 
lalitha sundaresan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear again its u,
i forgot to mention one important point regarding stateless and stateful
u can take the exmaple of calculator
stateless is a calculator which has no memory option but does calculations and forgets them.
staful bean is a claculator which does someprocessing and stores in memory so obviously a claculator with a memory option.
Cordially urs,
Lalitha.S
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic