java - Check for connections and eventually reconnect using dropwizard 0.9.2 and JDBI -


i'm using drowizard 0.9.2 jdbi connect mysql server. happen mysql database not active if app starts due async deployments. want app loop , check each 5 secs or whether can reach database.

how possible framework mentioned above?

just fyi, i've found solution works me.

this method checks connection. if returns false, i'll enter synchronous loop checks (and establish connection) when possible..

public boolean checkforconnection() { handle handle = null; try {   jdbi = factory.build(environment, config.getdatabasefactory(), "postgresql");    handle = jdbi.open(); } catch (exception e) {   logger.error("error while checking postgres connection.");   return false; } {   try {     if(handle != null){       handle.close();     }   } catch (exception e){     logger.error("error trying close connection");     return false;   } } return true; } 

unfortunately, can't use connectionfactory private member of dbi.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -