Session Beans Constraints

April 22, 2008 at 3:13 am (EJB, Unit 3)

Session Beans Constraints

 

  • Session beans disappear from the server, if
    • The session bean’s timeout value expires
    • The server crashes and is restarted
    • The server is shutdown and restarted
  • If any of these event occurs, state information of the bean is lost.

Solutions:

  1. Session timeout value is configurable so the timeout value can be increased.
  2. Server crashes and restarts are fairly rare events.
    1. The user can be notified that non-recoverable error has occurred and ask the user to try again later.
    2. A copy of the state of the bean can be cached at the client side and a new bean can be recreated in the event of original bean dies.
    3. Use a database on the server side to hold the state of the client’s conversation. If the session bean dies during the conversation, the client can reconnect and pass in a unique customer identifier to query the database to retrieve whatever state information was saved prior to the failure of the session beans.

 

  • A session bean’s state is not transactional. If the internal state of the bean is modified, the rollback will not affect the session bean’s internal state.

Solution:

  • The session bean’s state should be reset manually to whatever it was before the transaction began.
  • A stateless session bean cannot implement the SessionSynchronization interface. Because stateless session beans lack a conversational state and cannot hold a transaction across method invocations.
  • The final constraint on session beans is that they are not reentrant. If one thread is currently using a session bean, the container will throw a java.rmi.RemoteException in response to any other requests to connect to the session bean.

 

Post a Comment

You must be logged in to post a comment.