• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

session timeouts

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm working on a web application and in my web.xml file I have the following at the bottom of the file:

<session-config>
<!-- Value is in minutes -->
<session-timeout>15</session-timeout>
</session-config>

For general purposes this is needed, however, is there some way of dictating a longer timeout period depending on a special circumstance. For instance, let's say a student is going to write an online test which may take longer than 15 minutes - perhaps the test may take an hour or more to complete. Is there some way of setting up the timeout period based on the special circumstance?

Alan
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can set the timeout for a specific session using.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that session timeout is the inactive time - ANY request to the servlet that gets the session will reset the countdown.
WBB
 
Ranch Hand
Posts: 686
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you can do it by using Session Listerns.
Just explore it.
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, are you saying that I can do the following:

1. Since the default in the deployment descriptor is set for 15 minutes, when a client (a student) logs in the 15 minute countdown begins.

2. The student then decides to take a test. At this time I can override and reset the timeout period simply by calling: session.setMaxInactiveInterval(int seconds) precisely at the moment he begins the test?

Alan
[ August 06, 2005: Message edited by: Alan Shiers ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You still seem to be missing the point about session timeouts. Consider the following:

The student logs in - your program puts login information in the session and sets the time out for 15 minutes.
Possible results:
a. the student does nothing for 16 minutes - then attempts to take a test - the session having timed out, the login infomation has been lost - your code must detect this and send the user back to login.
b. the student starts a test before 15 minutes expires, your code puts test info in the session and sets a new timeout - say 10 minutes. All subsequent request - response cycles reset the servlet container's countdown mechanism for this session to the new time.

- AT ANY POINT in the student's taking of the test - after an hour or after 6 hours - if there is more than a 10 minute delay from one request-response cycle to the next - the session will be timed out and the student login information lost.

Each request resets the countdown timer.
Bill
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, when the student begins the test before the default 15 minute timeout period and knowing the test shouldn't take any longer than an hour, then resetting the timeout, at that moment, for say 1 hour 15 minutes shouldn't present a problem should it?

The student would complete the test within the hour and 15 minutes then submit before the session times out. Upon successful submission, I thought to reset the timeout period again back to the default of 15 minutes.

Alan
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i am having a similar problem of question.In fact i am not sure if i am having a problem too.

My contradiction is,

I am running a servlet(or jsp) for a long timed database query
(for examle for a report of a month,or year.It takes about 8 hours.).

I wonder whether session will die or not 8 hours later?

Default time out value is 30 mins passed in conf/web.xml.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The student would complete the test within the hour and 15 minutes then submit before the session times out. Upon successful submission, I thought to reset the timeout period again back to the default of 15 minutes.

Sounds like you've got it to me. You also may want to write code to reset the session timeout in the case of the student not finishing the test or having to quit the test.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am running a servlet(or jsp) for a long timed database query
(for examle for a report of a month,or year.It takes about 8 hours.).


You should not be thinking in terms of doing all this in a single request-response cycle. The first request should start the query in a separate Thread or even a separate application. It will be up to you to create some mechanism that will let the user come back later and recover the requested report. (Possibly a unique job number stored as a Cookie?)
Bill
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depending on your application and how much you care about each answered question in the test, it might make sense to keep saving data for each completed question. This way, if the session times out, you'll at least have some of the answered questions.

Another benefit is that you don't have to keep too much information in the session object ... especially if there are a lot of Strings or other immutable objects that can easily drain JVM's memory.

-stan
 
sinasi susam
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still not sure.
But process is still active in servlet's service method?So it will not timed out,will it.

How does the time out mechanism work?
Is it something setted when requested new sevlet or jsp?
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well
why dont you just check for the session at every request
or better use a session,session listener and a flag for the particular user
to check if his/her session is almost over.
if it is, you reset it to something you like.
[ August 09, 2005: Message edited by: lexander Bosco ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am still not sure.
But process is still active in servlet's service method? So it will not timed out,will it.


You appear to continue to be thinking of a single request that starts a multiple hour process using the request Thread.
The whole web server / servlet architecture is designed around a request-response cycle that occurs fairly rapidly. Don't try to turn it into something it is not designed for.
As I explained before, a new session gets the default timeout - which can be changed by the programmer. The servlet container is responsible for occasionally glancing at the sessions it holds (may be thousands of them) and destroying those that have not had activity within the timeout period.

Lexander -
please read this FAQ entry.
Bill
 
lexander Bosco
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks will
i will correct myself henceforth

thanks
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic