First page Back Continue Last page Graphics

...Stateful Session Beans


Notes:

For passivation to handle resources properly, any instance variables in the bean class that are not marked transient must contain one of the following at passivation time:
null. This is always safe.
A primitive value or reference to a Serializable object. These can be serialized.
A reference to an EJB-related object that the container knows how to handle: An EJBObject, EJBHome, SessionContext or UserTransaction.
The example that follows returns to the LegacyAppSessionBean class we used earlier in the course. The bean opens a socket to another server. Since sockets cannot be serialized, this bean uses ejbPassivate( ) and ejbActivate( ) to close / reopen the socket connection. Note that the latter has essentially the same logic as ejbCreate( ), since both are used to connect to the socket.
Turn to the next page for the code...