Skip to content

Commit a39938d

Browse files
izeyejhoeller
authored andcommitted
Polish DatabaseStartupValidator
(cherry picked from commit 8f21cb1)
1 parent edb3333 commit a39938d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ public void setValidationQuery(String validationQuery) {
7676

7777
/**
7878
* Set the interval between validation runs (in seconds).
79-
* Default is 1.
79+
* Default is {@value #DEFAULT_INTERVAL}.
8080
*/
8181
public void setInterval(int interval) {
8282
this.interval = interval;
8383
}
8484

8585
/**
8686
* Set the timeout (in seconds) after which a fatal exception
87-
* will be thrown. Default is 60.
87+
* will be thrown. Default is {@value #DEFAULT_TIMEOUT}.
8888
*/
8989
public void setTimeout(int timeout) {
9090
this.timeout = timeout;
@@ -127,11 +127,15 @@ public void afterPropertiesSet() {
127127
}
128128
catch (SQLException ex) {
129129
latestEx = ex;
130-
logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex);
131-
float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000;
132-
if (rest > this.interval) {
133-
logger.warn("Database has not started up yet - retrying in " + this.interval +
134-
" seconds (timeout in " + rest + " seconds)");
130+
if (logger.isDebugEnabled()) {
131+
logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex);
132+
}
133+
if (logger.isWarnEnabled()) {
134+
float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000;
135+
if (rest > this.interval) {
136+
logger.warn("Database has not started up yet - retrying in " + this.interval +
137+
" seconds (timeout in " + rest + " seconds)");
138+
}
135139
}
136140
}
137141
finally {
@@ -149,8 +153,8 @@ public void afterPropertiesSet() {
149153
"Database has not started up within " + this.timeout + " seconds", latestEx);
150154
}
151155

152-
float duration = (System.currentTimeMillis() - beginTime)*1f / 1000;
153156
if (logger.isInfoEnabled()) {
157+
float duration = ((float) (System.currentTimeMillis() - beginTime)) / 1000;
154158
logger.info("Database startup detected after " + duration + " seconds");
155159
}
156160
}

0 commit comments

Comments
 (0)