tags:

views:

146

answers:

2

I hava a fairly large war based web app. When I boot it up, Tomcat will allow connections immediately even if the app hasn't booted. Because of this, users get a blank page until the app is loaded.

I've seen some web apps where they display a "web app is starting, please wait" page while the app is loading. Is there a simple technique for java apps to do that?

+1  A: 

I suspect that your servlets are doing a lot of initialisation in the init() method. Can you offload that onto a separate thread, and record when that thread completes ? You can provide a servlet filter that checks the progress of that thread and interrupt requests (with a "please wait") message until the initialisation thread completes.

Brian Agnew
+1. `init()` is not limited to that of servlet, could be context listener (typical with Spring / some other frameworks) or another filter. You thus will have to be careful where you insert your filter or it won't even get control until everything is initialized.
ChssPly76
Seems like this sort of feature should be built into the container... like have the container display a 503 page while the app is still loading.
manalang
It does sound like some long running initialization is taking place on the first call to the web app, like perhaps connecting to a database and pre-populating some information. My suggestion would be to determine what is causing the delay, and then have a servlet that is loaded on start-up of the container begin this initialization process. A static field indicating when this initialization is complete could be used to decide whether to display a "please wait" page, or go straight to the normal web app.
monceaux
+1  A: 

When you work on a complex system, it's very difficult to avoid long wait at initializing or reloading stage. You have to tackle this issue from all aspects.

Here is some advice from my own experiences,

  1. Don't perform on-demand initialization, like connecting to database on first request. Do everything up front at sever startup.
  2. No gray status. It's either up or initializing. Kill the server if it partially works so load-balancer can do its work. Simply send "please wait" if status is not UP.
  3. Do initialization work in ContextListener if you can. Servlet.init() should only be used for things specific to the single servlet.
  4. Tomcat queues up requests during startup. So you need to perform long init tasks in a different thread so Tomcat can mark the context as UP and you can send that "please wait" message. We reduce the connector queue size also.
  5. Load-balancer/switch needs to be configured to a static "please wait" page when no server is up or all are too busy.
ZZ Coder