How is a bean state session restored when a client returns?

If a session with a bean state is passivated, its state is written to the hard drive, and then the bean instance will be freed to serve another request (at least this is my understanding). When the same client is active again, the bean will read the state from the hard disk to restore the state. But how does a bean instance know for which client which file it should read to maintain state?

I am very new to J2EE, so please forgive me if I ask very naive doubts. If I need to know any other topic to understand this, please point me in the right direction.

+7
source share
1 answer

It is best to visualize a Bean state (SfSB) session as very close to an instance of a regular Java class. You are viewing (or entering) an SfSB instance, and the container creates it for you and returns an instance. Then you work with this instance, like any other Java instance.

This means that you can save the instance to the session, serialize it to disk, etc.

The detail is that the instance you are working with is actually a proxy for the actual underlying SfSB instance. This is not SfSB itself.

When you make a call to the local proxy server in the bean, this container job should indicate that the Bean is in memory for you. Passivation and activation of the Bean is done behind the scenes for you (although you can connect to the process using the beans life cycle).

Any information that the passive SfSB should find for the container is stored in the proxy server you are working with, but this is not transparent to you. You have nothing to worry about.

Thus, in a typical network scenario, the life cycle will be that you get your Bean instance, save it in a web session, and then just use it as usual. If the container decides that it needs to passivate your Bean in order to free up space or something else, it will automatically passivate you. When your user returns, your application will pull the instance out of the web session and call it. At this time, if the Bean is passivated, the container will activate the Bean for you, automatically again. This whole mechanism depends on the container, but it is transparent to you. It is important to remember that you must enter the SfSB that you get from the container, like any Java object.

The final caveat is that if you allow SfSB to be passivated for too long, the container will automatically delete it for you.

+13
source