• 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 beans....

 
Ranch Hand
Posts: 160
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone.....!!!

regarding stateless and stateful beans i have 2 questions...

1) do we have to make the beans stateless explicitly ? i mean to say k if i have one variable i in my stateless bean, to make it stateless i have to write code manually ?

and for 2nd question i am posting my code here


NOW USING SERVLETS


output :

this is stateful local bean:-30
this is stateless local bean:-30
this is stateful remote bean:-30
this is stateless remote bean:-46

// here the state of all the beans is maintained and as i refresh the page output will be

this is stateful local bean:-31
this is stateless local bean:-31
this is stateful remote bean:-31
this is stateless remote bean:-47

USING JSP


output first time ...
Stateless local bean :- 1
Stateful local bean :- 1
Stateless remote bean :- 1
Stateful remote bean :- 1

output when page is refreshed...

Stateless local bean :- 1
Stateful local bean :- 1
Stateless remote bean :- 2
Stateful remote bean :- 1


NOW I AM NOT GETTING THIS BEHAVIOUR....WHY IN JSP THE STATE FOR ONLY STATELESS REMOTE BEAN IS MAINTAINED ?
IS IT BUG OF EJB 3.1 ? SOME EXPERT PLEASE COMMENT ON THIS..

Thanks in advance....
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


do we have to make the beans stateless explicitly


Yes. If you add state to a stateless bean any other way you are writing a bug.
 
ankur trapasiya
Ranch Hand
Posts: 160
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so is it our responsibility to make a bean stateless ?... Do we have to make all the member variables stateless explicitly or container manages their state ?
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Do we have to make all the member variables stateless explicitly or container manages their state ?



There is nothing like making member variables stateless.

Stateless in case of Stateless session beans means that the client will never know which instance from the instance pool of the stateless session bean is serving the request. If you try maintain state (For e.g. Name of the Client) using an instance variable in SLSB, then you will never have guarantee that your next method call will be handled by the same SLSB instance that served you earlier. I hope that I am helping you to understand this.

Let me try to illustrate this as well using a Pseudo Code.
1) Client invokes SLSB.setClientName()
2) SLSB.method1 -> sets some instance variable of SLSB -> this.clientname - "amit"
3) Client invokes SLSB.getClientName() - This may or may not return you the expected value i.e. "amit" which was set in #2.

Please note that SLSB generally exposes the business functions, I just took help of set/get as it is easier to understand statelessness using this.

Regards,
Amit



 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic