First page Back Continue Last page Graphics

Stateful Session Beans...


Notes:

Since stateful beans can be idled by an inactive client, the container may passivate them. It does so by serializing the instance to temporary storage, then letting it be garbage collected. When the instance is needed again, the container activates it by deserializing it back into memory.
The SessionBean methods ejbPassivate( ) and ejbActivate( ) are called just before the bean instance is swapped out of memory and just after it is swapped into memory, respectively.
Many beans can leave these methods empty. But a given bean may need them to release / restore other resources that wouldn't be serialized, such as socket connections and threads. These resources are held in instance variables marked transient (which means the serialization process will ignore them).
Stateful Session Bean as Limo
Continuing the transportation analogy, stateful session beans are like limousines. You (the client) call for a limo (the bean) to take you to the airport. Your luggage in the trunk is the bean’s state. Along the way you ask the driver to stop at your office so you can pick up some papers. The driver stops and waits for you, engine running, your luggage still in the trunk. But you are gone a long time, and the driver grows impatient at being idle so long. To passivate the limo and conserve resources, the driver simply turns off the engine. When you reappear, the driver restarts the engine and you resume your journey.