First page Back Continue Last page Graphics
...Stateful Session Beans
Non-transient fields must contain one of these:
- null, primitive or reference to a Serializable object
- An EJBObject or EJBHome reference
- A SessionContext or UserTransaction reference
See example in notes...
- Bean closes socket on passivate, opens on activate
- Note that ejbActivate( ) is similar to ejbCreate( )
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...