views:

196

answers:

2

While serving flash based training material users peroidically experience a HttpSession session timeout. Currently the inactivity timeout is set to default (30mins).

Questions:

  1. Would it be a good idea to attempt to increase MaxInactiveInterval for any user who is requesting a training flash video to prevent the timeouts?

  2. Would a better approach be to use a servlet lifecycle listener to re-activate the HttpSession if the HttpSession is associated with viewing training content? -- this may allow for more precise control over when the HttpSession object is going to timeout.

  3. Only a small percentage of user's will actually be viewing this material at any one time, is there a performance penalty that should be considered for doing this?

+1  A: 

Is the flash video embedded in an HTML page? If so, perhaps you could have an AJAX call on the page that periodically sends a "heartbeat" to the server to keep the session alive.

Kevin
Here is a good explanation: http://ajaxpatterns.org/Heartbeat
Aito
A: 

Rather fire ajax polls in the background.

Here's an SSCCE with a little help of jQuery. Just copy'n'paste'n'run it (and change the flash object to suit your actual code).

<!doctype html>
<html lang="en">
    <head>
        <title>SO question 2290101</title>
        <script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
        <script>
            $(document).ready(function() {
                setInterval(function() {
                    $.get('poll');
                }, ${(pageContext.session.maxInactiveInterval - 10) * 1000});
            });
        </script>
    </head>
    <body>
        <object type="application/x-shockwave-flash" ... >
            ...
        </object>
    </body>
</html>

Here ${pageContext.session.maxInactiveInterval} returns the remnant of seconds the session has yet to live (and is been a tad shortened -just to be in time with poll- and converted to milliseconds so that it suits what setInterval() expects). The $.get('poll') should call a servlet which is mapped on an url-pattern of /poll and contains basically the following line in the doGet() method.

request.getSession(); // Keep session alive.

That's it.

BalusC