Browse Source

Polish DatabaseStartupValidator

pull/1820/head
Johnny Lim 8 years ago committed by Juergen Hoeller
parent
commit
8f21cb1a7c
  1. 10
      spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java

10
spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java

@ -76,7 +76,7 @@ public class DatabaseStartupValidator implements InitializingBean {
/** /**
* Set the interval between validation runs (in seconds). * Set the interval between validation runs (in seconds).
* Default is 1. * Default is {@value #DEFAULT_INTERVAL}.
*/ */
public void setInterval(int interval) { public void setInterval(int interval) {
this.interval = interval; this.interval = interval;
@ -84,7 +84,7 @@ public class DatabaseStartupValidator implements InitializingBean {
/** /**
* Set the timeout (in seconds) after which a fatal exception * Set the timeout (in seconds) after which a fatal exception
* will be thrown. Default is 60. * will be thrown. Default is {@value #DEFAULT_TIMEOUT}.
*/ */
public void setTimeout(int timeout) { public void setTimeout(int timeout) {
this.timeout = timeout; this.timeout = timeout;
@ -127,13 +127,17 @@ public class DatabaseStartupValidator implements InitializingBean {
} }
catch (SQLException ex) { catch (SQLException ex) {
latestEx = ex; latestEx = ex;
if (logger.isDebugEnabled()) {
logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex); logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex);
}
if (logger.isWarnEnabled()) {
float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000; float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000;
if (rest > this.interval) { if (rest > this.interval) {
logger.warn("Database has not started up yet - retrying in " + this.interval + logger.warn("Database has not started up yet - retrying in " + this.interval +
" seconds (timeout in " + rest + " seconds)"); " seconds (timeout in " + rest + " seconds)");
} }
} }
}
finally { finally {
JdbcUtils.closeStatement(stmt); JdbcUtils.closeStatement(stmt);
JdbcUtils.closeConnection(con); JdbcUtils.closeConnection(con);
@ -149,8 +153,8 @@ public class DatabaseStartupValidator implements InitializingBean {
"Database has not started up within " + this.timeout + " seconds", latestEx); "Database has not started up within " + this.timeout + " seconds", latestEx);
} }
float duration = (System.currentTimeMillis() - beginTime)*1f / 1000;
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
float duration = ((float) (System.currentTimeMillis() - beginTime)) / 1000;
logger.info("Database startup detected after " + duration + " seconds"); logger.info("Database startup detected after " + duration + " seconds");
} }
} }

Loading…
Cancel
Save