1

I am runnig a web application on tomcat 5.5.

How can I force dump of a session into disk

  1. on each request
  2. on each interval of time
skaffman
  • 398,947
  • 96
  • 818
  • 769
Spiderman
  • 9,602
  • 13
  • 48
  • 56

2 Answers2

0

Question 1 could be done using a filter or valve:

    public void doFilter(ServletRequest request, ServletResponse response,
                FilterChain chain) throws java.io.IOException, ServletException {
            HttpServletRequest req = (HttpServletRequest) request;
            HttpServletResponse res = (HttpServletResponse) response;
            HttpSession session = req.getSession(false);
            if(session != null) {
            dumpSession( session );
            }
            chain.doFilter(request, response);
        }
}

For Question 2 see this discussion

stacker
  • 68,052
  • 28
  • 140
  • 210
  • regarding solution one - I'd rather provide a solution that can be given using configuration files without code change. regarding solution 2 and the discussion you refered to- Assuming that the configuration is through context.xml file and 'manager' object, I couldn't figure what is the attribute that control the time-interval in which the session will be persisted – Spiderman May 26 '10 at 08:18
  • in addition regarding your code- 'dumpSession()' is not a known API – Spiderman May 26 '10 at 10:35
  • @Spiderman Right this left to the reader to implement this to write whatever format ;-) – stacker May 26 '10 at 10:46
0

Look at Persistent Manager http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html Setting maxIdleBackup and maxIdleSwap to 0 or near-zero time would persist session on every request. Setting these parameters to bigger value will give You dump in intervals.

Bartek Jablonski
  • 2,649
  • 24
  • 32