Alex Rivera | Logout

Solution to the long running query problem in a web application (asynchronous request)

Asked 2009-12-30T09:32:42.340
10

Here is the problem

A user of an enterprise web application is performing a task that results in a long (very long) database query (or other long processing intensive task)

Problems:

  • Request timeout - after a while the user may get a request timeout
  • Session timeout - if no session keeping methods are used, a session timeout can occur
  • Request thread lock
    • since the request thread is not returning, it may block new requrests (if reaches the pool limit)
    • In some application servers the server's health status might trigger a forced restart of the node or application(due to a long running request thread)
  • If the user leaves the page:
    • the transaction is not canceled - resulting in useless processing no one will benefit from
    • the user can't return to see the results after they complete
  • no progress indication - the user just waits for the page to refresh

There are several solutions I came up with, but I'm not sure I know which is better (in all aspects, peformance, best practice, elegance and maintainability) and I would like to know what is your recommended solution, and if there is a solution that I missed? (probably yes, and many)

The bad solution: use the request thread as a worker thread,save progress state in the session, have an AJAX call check the status (in the session) in another paralel request

The compromise solution: create your own thread pool, handle a monitoring thread, a worker thread and take care of clustering by syncronizing the states in either a distrubuted transactional cache or persistant storage. this releases the request, but creats threads the application server is not aware of, and won't close in undeployment. Its up to you to shutdown threads in a clean way, and there is always a chance you will end up leaking something. This is not the J2EE way to do it e

Edit
Report

1 Answer

1

Show a message to the user that "Your request is accepted and will take an hour to get updated"

You create a table which stores all these transactions and process these in a batch on server.

User would not have to wait for long and he will be happy to see the message. You can send a confirmation email once your the transaction is processed.

This is the best solution I think.

answered 2009-12-30T12:10:19.303

Your Answer