Tomcat Session Replication

Session replication is configured in /conf/server.xml. Here is an example that uses multicast for instance discovery (Tomcat 5.5).

    <Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
         managerClassName="org.apache.catalina.cluster.session.DeltaManager"
         expireSessionsOnShutdown="false"
         useDirtyFlag="true"
         notifyListenersOnReplication="true"
         printToScreen="true">

        <Membership
            className="org.apache.catalina.cluster.mcast.McastService"
            mcastAddr="228.0.0.4"
            mcastPort="45564"
            mcastFrequency="500"
            mcastDropTime="3000"/>

        <Receiver
            className="org.apache.catalina.cluster.tcp.ReplicationListener"
            tcpListenAddress="auto"
            tcpListenPort="4002"
            tcpSelectorTimeout="100"
            tcpThreadCount="6"/>

        <Sender
            className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
            replicationMode="pooled"
            ackTimeout="150000"
            waitForAck="true"/>

        <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
               filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>

        <Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                  tempDir="/tmp/war-temp/"
                  deployDir="/tmp/war-deploy/"
                  watchDir="/tmp/war-listen/"
                  watchEnabled="false"/>

        <ClusterListener className="org.apache.catalina.cluster.session.ClusterSessionListener"/>
    </Cluster>

You also have to set the jvmRoute attribute on the <Engine> element in server.xml, like this

<Engine jvmRoute="tomcat2" name="Catalina" defaultHost="MyHost">

. Note: if you are using mod_jk as a poor man's load balancer, the value of the jvmRoute has to match the name listed in the workers.properties file references by the mod_jk configuration.

See your Tomcat documentation for details.