All (especially Filip ;-),

I have a <distributable/> web app.  When run on a single, non-clustered
Tomcat, it behaves correctly, maintaining the session state essentially
forever.  When run in a cluster, however, the session state is lost (the
session is clearly destroyed.)

The application essentially refreshes a page at less then the timeout value
specified in web.xml.  This should maintain the last access time (and it
does for non-clustered environments.) 

This happens on 5.5.12, and 5.5.17 in both Windows and Linux environments.

I've boiled this down to a very simple JSP, web.xml, and session listener
for anyone who wants to take a stab at it.  The files are included below.
Session timeout is 2 minutes / 120 seconds, and meta-refresh is at 90
seconds.  Here is the output of three page loads for index.jsp:

1st load:

This is a simple index.jsp
Session ID                        6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
Session created at            2006-05-128 11:40:29.587
Session last accessed at        2006-05-128 11:40:29.587
Current time is             2006-05-128 11:40:29.587
Session max inactive interval   120

(New session, all three timestamps are identical)

2nd load (1st refresh):

This is a simple index.jsp
Session ID                        6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
Session created at            2006-05-128 11:40:29.587
Session last accessed at        2006-05-128 11:40:29.587
Current time is             2006-05-128 11:41:59.634
Session max inactive interval   120

(meta-refresh at 90 seconds, current time is ~90 seconds later then last
accessed time)

3rd load (2nd refresh):

This is a simple index.jsp
Session ID                        6019F1DDD1DC9162A88CD0A4DD0291A2.tim9009
Session created at            2006-05-128 11:43:29.665
Session last accessed at        2006-05-128 11:43:29.665
Current time is             2006-05-128 11:43:29.665
Session max inactive interval   120

(Session has been destroyed.  The SessionListener logs the destruction,
about 2 minutes after the last access time from the first page load.

Time: 2006-05-08 11:43:08,806
Thread: ContainerBackgroundProcessor[StandardEngine[Catalina]]
Message: destroy session [ID=6A4E1FB6E52889FBC6BAF8D298375E27.tim9009,
CRE=Mon May 08 11:40:29 EDT 2006, LAST=Mon May 08 11:40:29 EDT 2006,
TMO=120]

Note that the LAST (access time) was not updated by request #2.

)


Here are the relevant files.  I will mail any of the developers a .zip with
everything included (an entire Eclipse project in fact) if requested.

8<8<8<8<8<8<8<8< Simple.xml / context.xml 8<8<8<8<8<8<8< <Context
  docBase="C:/Projects/simple"
  reloadable="true">
</Context>

8<8<8<8<8<8<8<8< index.jsp 8<8<8<8<8<8<8<8< <%@ page import="java.util.Date"
%> <%@ page import="java.text.SimpleDateFormat" %> <%
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD
HH:mm:ss.SSS"); %> <html> <head> <META http-equiv='Refresh' content='90'>
</head> <body> <h1>This is a simple index.jsp</h1> <table> <tr> <td>Session
ID</td><td><%=session.getId()%></td>
</tr>
<tr>
<td>Session created at</td><td><%=format.format(new
Date(session.getCreationTime()))%></td>
</tr>
<tr>
<td>Session last accessed at</td><td><%=format.format(new
Date(session.getLastAccessedTime()))%></td>
</tr>
<tr>
<tr>
<td>Current time is</td><td><%=format.format(new Date())%></td> </tr> <tr>
<td>Session max inactive
interval</td><td><%=session.getMaxInactiveInterval()%></td>
</tr>
</table>
</body>
</html>

8<8<8<8<8<8<8<8< web.xml 8<8<8<8<8<8<8<8< <?xml version = '1.0' encoding =
'UTF-8'?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
    version="2.4">

  <distributable/>
  <!-- Display name is used as the mBean name, so it can't contain a ,   -->
  <display-name>Simple</display-name>
  <description>Simple Web Application</description>

  <listener id="SessionLifecycleListener">
    <description>Session Lifecycle Event Listener</description> 
    <display-name>SessionLifecycleListener</display-name> 
    <listener-class>simple.SessionLifecycleListener</listener-class>
  </listener>
  
  <session-config>
    <session-timeout>2</session-timeout>
  </session-config>
</web-app>

8<8<8<8<8<8<8<8< SessionLifecycleListener.java 8<8<8<8<8<8<8<8< package
simple;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SessionLifecycleListener implements HttpSessionListener {
    private final static Log logger =
LogFactory.getLog(SessionLifecycleListener.class);

    public void sessionCreated(HttpSessionEvent arg0) 
    {
        final HttpSession session = arg0.getSession();
        dumpSession("create", session);
    }

    public void sessionDestroyed(HttpSessionEvent arg0) 
    {
        final HttpSession session = arg0.getSession(); 
        dumpSession("destroy", session);
    }
    
    private void dumpSession(String verb, HttpSession session) 
    {
        logger.debug(verb + " session " + formatSession(session));
    }

    public final static String formatSession(HttpSession session)
    {
        return session == null ? "<null session>" :
            "[ID=" + session.getId() + ", CRE=" +
            new Date(session.getCreationTime()) + ", LAST=" +
            new Date(session.getLastAccessedTime()) + ", TMO=" + 
            session.getMaxInactiveInterval() + "]";
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to