refactor code, use StringBuilder & remove SimpleDateFormat

This commit is contained in:
shaojin.wensj
2019-01-29 16:13:55 +08:00
parent 9cd0354309
commit 0baed9f7ca
3 changed files with 106 additions and 83 deletions
@@ -1477,19 +1477,26 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
&& activeCount >= onFatalErrorMaxActive) {
connectErrorCountUpdater.incrementAndGet(this);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String errorMsg = "onFatalError, activeCount " + activeCount
+ ", onFatalErrorMaxActive " + onFatalErrorMaxActive;
StringBuilder errorMsg = new StringBuilder();
errorMsg.append("onFatalError, activeCount ")
.append(activeCount)
.append(", onFatalErrorMaxActive ")
.append(onFatalErrorMaxActive);
if (lastFatalErrorTimeMillis > 0) {
errorMsg += ", time '" + format.format(new Date(lastFatalErrorTimeMillis)) + "'";
errorMsg.append(", time '")
.append(StringUtils.formatDateTime19(
lastFatalErrorTimeMillis, TimeZone.getDefault()))
.append("'");
}
if (lastFatalErrorSql != null) {
errorMsg += ", sql \n" + lastFatalErrorSql;
errorMsg.append(", sql \n")
.append(lastFatalErrorSql);
}
throw new SQLException(errorMsg, lastFatalError);
throw new SQLException(
errorMsg.toString(), lastFatalError);
}
connectCount++;