Alex Rivera | Logout

How to handle database crashes (Glassfish/MySQL)?

Asked 2012-10-26T11:18:35.587
8

I have a 3-tiered application with Glassfish 3.1.2.2, MySQL database and a Swing client application. Is it somehow possible to handle a database server crash?

I tried to stop the MySQL service during my application is running. Then I get javax.ejb.EJBAccessException exceptions everytime I try to access the database through one of my facade session beans.

I want to notify the user that the database is currently down. furthermore i want to set my application in kind of a "sleep-mode" until the database is up and running again.

What would be a good (and possibly easy) approach to handle such a scenario?

Thanks for your help in advance!

Edit
Report

1 Answer

1

On it's own Connection Pool will monitor the state of the database. You could create an interceptor and pick up when db goes down. The container will try to reconnect, but you won't necessarily know when it's successful. Once you detect the error you'd need to set a semaphore somewhere. Then you'd have to fire up a timer to periodically check the state of the db and to reset the semaphore once it comes back. Last, you'd have to code your app to respect the semaphore.

This is a high level suggestion. good luck.

Alternatively, you might be able to hook all the events using JMX... I'm not sure though.

answered 2012-10-28T15:25:53.363

Your Answer