Jayesh
Jayesh

Reputation: 6111

Tomcat Session Timeout while processing Request

I face a scenario where everything works fine with keeping session.setMaxInactiveInterval(15*60) //15 minutes

Now, there is one request in application where number of users are getting saved, which takes more then 15 minutes at server side as internally many operations are involved while saving each user.

When saveUser operation is performed from browser, request received at server, starts processing, after 15 minutes client see "Session Time out" but user saving operation still going on.

I want to avoid this scenario, and need is when request is received by server at that time till the time it responds back to client don't considered in-between time as inactive time.

I can very well do it by making setMaxInactiveInterval(-1) as first line of my method saveUser and just before giving response as setMaxInactiveInterval(15*60).

I am looking for standard approach or this is the standard approach to follow? Is there any inbuilt Tomcat configuration provided for such scenario?

Upvotes: 0

Views: 728

Answers (1)

beny23
beny23

Reputation: 35008

The standard Java EE approach for this would be as follows:

  • Instead of doing all the processing in the web-layer, put all the details on a JMS queue and return the request straight away.
  • The data would be taken off the JMS queue by a worker (possibly on a different server, as you wouldn't want to have the load of creating something for 15 minutes on your web layer)
  • Once the data is create for the user a notification would be generated (e.g. the browser could query every 30 seconds whether the user generation has finished).

N.B. blocking a thread in a server for 15 minutes is a very bad idea, because essentially it means that your servlet container wouldn't be able to do anything else with that thread. Imagine if a large number of those requests came in at the same time, your web layer would probably buckle under the pressure...

N.B.2: 15*50 does not make 15 minutes

Upvotes: 1

Related Questions