permaculture playing cards
The moose likes Servlets and the fly likes Will Session timeout while the servlet is being executed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Will Session timeout while the servlet is being executed?" Watch "Will Session timeout while the servlet is being executed?" New topic

Will Session timeout while the servlet is being executed?

Sajee Joseph
Ranch Hand

Joined: Jan 17, 2001
Posts: 200

I invoke a servlet which inturn invokes a few DB2 sps to get the job done.
Each of the DB2 sps takes approximately 20 mins to complete ( There is some complex logic in each). In the midst of this processing is there any possibility of session expiring? I mean, assume that my session time out is 30 mins. And if my servlet takes 45 mins to execute, will my session time out in the middle of processing? If yes, then how do i prevent this from hapanning?

Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
No need to worry about the session expiring. The request will time out long before that might possibly happen.

This will never work.

ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

It's the container that checks for session validity.

This means that once a request is accepted by the container to contain a valid session and the associated server side process invoked to service it, there isnt any danger of the session being invalidated at any point further on in that request cycle, irrespective of the length of the time taken by the process to service the request.

However the next request may not have a valid session. By the time the response is sent to the browser and the client makes the next request, the time elapsed between that request and the previous one would be greater than the max inactive interval.

This is because the Servlet/Jsp takes a longer time to process the first request than the max inactive interval of the session. The container unaware of this, just checks the time between 2 subsequent requests and finds that the difference is greater than the max inactive interval and invalidates the session.

The above maybe container specific and you have to test it out on the server you are working with. You should consider setting the max inactive interval to a value greater than the sum of the maximum time that the servlet may take to process the request and the maximum think time.

ie session timeout > max server side process time + max allowable think time

ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Jeroen is probably right. I hadnt, in my post, considered the possibility of the request timing out.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The most common pattern used for long runninng server processes is the polling webpage.

The user submits the request.
The servlet kicks off the long running process, asynchronously, and returns immediately.
The webpage has a meta refresh tag that causes it to refresh itself every n secconds.
Each time the polling page refreshes, it checks the status of the long running process. If it's done, the results of the process are returned, otherwise, the polling page is returned.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Will Session timeout while the servlet is being executed?
jQuery in Action, 3rd edition