InfoCenter Home >
4: Developing applications >
4.4: Personalizing applications >
4.4.1: Tracking sessions >
4.4.1.1: Session programming model and environment >
4.4.1.1.5: Using sessions in a clustered environment

4.4.1.1.5: Using sessions in a clustered environment

Consider the following issues regarding how session management works within a clustered environment. Clustered environments include any environments in which requests are being handled by multiple Web servers, multiple application servers, or both. See section 7 for more about clustering and workload management.

Session support requires an affinity mechanism

Session clustering requires an affinity mechanism so that all requests for a particular session are directed to the same Java Virtual Machine (JVM) in the cluster. One such solution provided by IBM WebSphere Application Server is Session Affinity in a server group; this solution is available as part of the WebSphere plug-ins for Web servers.

For use in a clustered environment, objects placed in persistent sessions must be serializable

To make your applications portable to a clustered environment, you must make any objects placed in a persistent session serializable. If you place an object that does not implement the Serializable interface, you lack a way to propagate the object with a given session, disallowing proper persistence among servlets in the cluster.

(If failover support for the session is not required, implementing the Serializable interface is not necessary. If you use the Session Affinity plug-in, you can now choose to use only the in-memory HttpSession object. This is possible because the plug-in redirects all requests that refer to a given HttpSession object to the server group in which the session was initially created and resides.)

In addition to java.io.Serializable objects, Session Manager also supports the placement of the following objects into HttpSession for clustered (distributable) environments:

  • javax.ejb.EJBObject
  • javax.ejb.EJBHome
  • javax.naming.Context
  • javax.transaction.UserTransaction

EJBObject, EJBHome, and Context objects can be placed directly into HttpSession. For UserTransaction objects in clustered environments, use com.ibm.websphere.servlet.session.UserTransactionWrapper, which requires you to include the InitialContext object from which this transaction object was retrieved. (If failover support for the session is not required, you can place the UserTransaction object directly into HttpSession.)

Within a Web application that is marked as distributable, all objects that are placed into the session must implement the Serializable interface; otherwise, an IllegalArgumentException is thrown.

For additional notes on programming for clustered environments, see the related information.

Session binding occurs on a certain application server in the cluster

When HttpSessionBindingListener and HttpSessionBindingEvent are used in a clustered Web server environment, the event is fired in the application server on which the session is currently being processed. The action will occur in situations where:

  • A listener is put into a session
  • A listener is removed from a session
  • The servlet explicitly invalidates the session that contains listeners

If the session times out, this (unbound) event may be fired in any one of the application servers in the cluster.

Certain changes might require restarting all Session Managers in a cluster

See the related information for details.

Go to previous article: Deciding between single-row and multirow schema for sessions Go to next article: Tuning session support

 

 
Go to previous article: Deciding between single-row and multirow schema for sessions Go to next article: Tuning session support