aspose file tools*
The moose likes Servlets and the fly likes Question about setMaxInactiveInterval(int seconds) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question about setMaxInactiveInterval(int seconds) " Watch "Question about setMaxInactiveInterval(int seconds) " New topic
Author

Question about setMaxInactiveInterval(int seconds)

Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
The HttpSession documentation says that "A negative time indicates the session should never timeout". Of course, when it says a negative time, it refers to the parameter "int seconds" of this method.

What does it really mean? Does it mean that the session should be alive until the browser is closed?

Thanks.
Barron Greig
Greenhorn

Joined: Jan 26, 2002
Posts: 8
The server does not know if the browser has been closed. The session will stay alive until the servlet engine is shut down.
Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
Then how should we handle this? I mean how do we intelligently maintain a session?
Barron Greig
Greenhorn

Joined: Jan 26, 2002
Posts: 8
The servlet engine is doing all the hard work of maintaining the session for you using either cookies or URL rewriting. The maxInactiveInterval (defaults to 20 minutes) will mean that if the client doesn't send another request for 20 minutes, the servlet engine is free to expire that session. If you have high demand then you might end up with a build up of "stale" sessions. You could shorten the interval, but take into account that if the interval was a few seconds, then every time they paused to think, their session would time-out on them. If you don't have high demand you could maybe make the maxInactiveInterval longer so they could go away and cook their dinner before completing purchase of Widgets from your online store.
If you do change maxInactiveInterval, I recommend changing it in the web.xml. There is a <session-config> parameter called <session-timeout> that will have the same effect.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about setMaxInactiveInterval(int seconds)