How to make App server to start even if database is down?
Asked Answered
P

2

3

I am using spring & hibernate. my application has 3 modules. Each module has a specific database. So, Application deals with 3 databases. On server start up, if any one of the databases is down, then server is not started. My requirement is even if one of the databases is down, server should start as other module's databases are up, user can work on other two modules. Please suggest me how can i achieve this? I am using spring 3.x and hibernate 3.x. Also i am using c3p0 connection pooling. App server is Tomcat.

Thanks!

Pomology answered 20/4, 2012 at 10:37 Comment(4)
What's with all that bold text?Consultant
Have you tried it? You wouldn't know whether a database is down until you connect to it, so unless c3p0 prevalidates all its connections, you wouldn't know that a particular database is down until you try to use it. By that time your application will have already started.Isometry
Hi Beny,Thanks for your reply. if prevalidation of c3p0 fails, i mean if one of the database is down, server will not start right? Please correct me if i am wrong. Thanks!Pomology
@Isometry your answer is a good option too. it helped me. please put it as a proper answer to be able to vote on that.Isidor
C
5

I would use the @Configuration annotation to make an object who's job it is to construct the beans and deal with the DB down scenario. When constructing the beans, test if the DB connections are up, if not, return a Dummy Version of your bean. This will get injected into the relevant objects. The job of this dummy bean is to really just throw an unavailable exception when called. If your app can deal with these unavailable exceptions for certain functions and show that to the user while continuing to function when the other datasources are used, you should be fine.

@Configuration
public class DataAccessConfiguration {

  @Bean
  public DataSource dataSource() {
   try {
     //create data source to your database 
     ....
     return realDataSource;
   } catch (Exception) {
     //create dummy data source
     ....
     return dummyDataSource;
   }
  }
}
Chanell answered 22/4, 2012 at 16:5 Comment(1)
Hi BruceLowe, Thanks for your reply. Some how i can make app server up even if one of the data base is up. but once user start using other modules, if data base is up, in the middle and user tries to access it , how can i configure pooling only for that database? ThanksPomology
I
1

This was originally a comment:

Have you tried it? You wouldn't know whether a database is down until you connect to it, so unless c3p0 prevalidates all its connections, you wouldn't know that a particular database is down until you try to use it. By that time your application will have already started.

Isometry answered 26/2, 2013 at 11:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.