Mike,

Doing this with pure J2EE Servlet code, I would use three components. First, use the Context Listener to check the Database on start up, if no DB connectivity set a ApplicationContext attribute to that effect. The second part would be a javax.servlet.Filter which checks the status of the ApplicationContext attribute forwarding to an error page if the attribute indicates database connectivity issues. Third, instead of just a String, I'd use a self-updating object as the attribute in the ApplicationContext. This self updating object runs an internal timer thread which tests connectivity at a fixed interval setting the DB status to up or down. This third component is optional.

Regarding your issue not wanting to start certain servlets if the Database is down, you could carry out a DB connectivity test in the base class to all your servlets, skipping initialization if no connectivity.

Steve

Mike Miller wrote:

Hi,
I am looking for options to prevent my web application from being
available if our database is not available. I've used context listeners
in the past, but since you can return a bad return code they don't like
the cleanest approach.


I have tried registering a context listener and then throwing a
RuntimeException if the database is not available but that seems like a
kludge.

Any other options?



Thanks in advance,

Mike




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to