Vishnu G S
Vishnu G S

Reputation: 714

Java- feasibility of session timeout limit

Is it feasible to set unlimited session time out programmatically using HttpSession. setMaxInactiveInterval(int seconds) or using

<session-config>
    <session-timeout>-1</session-timeout>
</session-config>

? Will this lead to any overhead?

Upvotes: 0

Views: 732

Answers (4)

Lucky
Lucky

Reputation: 17345

Yes. It is possible to programmatically set the session timeout via a java servlet or jsp page using the setMaxInactiveInterval method,

HttpSession.setMaxInactiveInterval(int seconds)

Here the int value in seconds specifies the time, in seconds, between client requests before the servlet container will invalidate this session.

An interval value of zero or less indicates that the session should never timeout.

However, many HTTP servers in general use are configured to drop persistent connections after a certain period of inactivity in order to conserve system resources, quite often without informing the client. So keeping up the connectins alive may lead to java.lang.OutOfMemoryError: GC overhead limit exceeded error.

Out Of Memory Error

More open connections requires more memory and more requests hit your server and eventually causes your server to crash.

Upvotes: 2

RealSkeptic
RealSkeptic

Reputation: 34608

The documentation says that calling that method with a negative number of seconds will cause the session to never time out.

Overhead depends on the implementation, but I suppose (as can be seen in the source code for Catalina's StandardSession) it would cause less overhead than a limited session time, because the server does not need to do the cleanup required after the expiry time.

Upvotes: 0

Vishnu G S
Vishnu G S

Reputation: 714

The answer lies in this post: http://www.theserverside.com/discussions/thread.tss?thread_id=26490 The server will run out of memory.

Upvotes: 0

Naresh kumar
Naresh kumar

Reputation: 1069

Through config file is preferred, Reason being able to change timeout limit in one place if the question is whether to go with config file or calling setMaxInactiveInterval(int seconds) within code.

And yes we can set unlimited timeout limit through config settings.

Upvotes: 0

Related Questions