vShyam Sundar wrote:Implement a bean with two instance variables with default values, on the first call to bean from a client, update the instance variables with different values. Call the bean again with the same instance that you created first, your instance variable state will be maintained, whereas if you invoke with different instances then you will get the default values.This happens regardless of whether it is a stateless or stateful bean
vShyam Sundar wrote:But with respect to SLSB when i tried looking up the bean multiple times,I got the default values assigned to instance variables on every look of SLSB, Not the values assigned during previous look up calls. This might be because of the pooling mechanism as i might have at the max looked up two or three bean instances whereas the pool might have more than two instances.
When a bean is a singleton, it simply means that every time you access the bean, you will get a reference to the same object with the same state
With Stateful bean a new instance will always be created whenever a request arrives.
it is similar to HTTPSession for keeping user specific information
vShyam Sundar wrote: In other words i can say it is similar to HTTPSession for keeping user specific information when accessed from a stand alone clients. If you are aware of this can you post a sample code for the same.
vShyam Sundar wrote:when I declare my bean as stateful, A new bean instance is created for every request/subsequent request(Create method in the bean is called for every request).
Whereas for stateless bean, a bean instance is created once(Create method in the bean is called only once) and for every request/subsequent request the same values are getting printed.
Am i missing something here?
vShyam Sundar wrote: because the moment you navigate from screen 1 to screen 2, you need to look up your bean again
vShyam Sundar wrote:Whereas for stateless bean, a bean instance is created once(Create method in the bean is called only once) and for every request/subsequent request the same values are getting printed
vShyam Sundar wrote:So if it is a web application, I have to maintain the stateful bean instance in the HTTP session right? and what about native or stand alone applications?