1

I have the following problem:

I am writing a web application with servlets and JSP which should query a separate service. But the query takes a lot of time - around 30 seconds.

The structure of my app is simple - Filter->Controller->jsp. I was thinking what if in the filter I send the request into a separate thread to be processed while the controller goes on executing its job. What shall I do in order to make the querying process and controller processing simultaneous? + I need the query to be renewed every 5 mins (so that the user does have the relevant info). What is the optimum way to do that?

informatik01
  • 16,038
  • 10
  • 74
  • 104
Artem Moskalev
  • 5,748
  • 11
  • 36
  • 55

1 Answers1

1

Use a ServletContextListener to start a thread when the web application starts.

The thread should write the data into the ServletContext (e.g. via setAttribute()).

The ServletContextListener should terminate the thread when the application is stopped.

The Servlet should read the data from the ServletContext as it needs it.

Mark Thomas
  • 16,339
  • 1
  • 39
  • 60