2023年11月29日发(作者:)

关于Druid重试机制的问题及解决⽅案

在昨天项⽬开发中,使⽤了Druid作为数据库连接池,当数据源密码错误时,报出了以下错误:

2019-04-09 10:09:36 [Druid-ConnectionPool-Create-2053591126] [ ataSource ] [ 53 ] [ ERROR ] create connection SQLExc

eption: Access denied for user 'malluser'@'*.*.*.*' (using password: YES)

at SQLException(:545) ~[:6.0.6]

at SQLException(:513) ~[:6.0.6]

at ateException(:115) ~[:6.0.6]

at NewIO(:1606) ~[:6.0.6]

}

();

break;

}

long discardCount = dCount;

boolean discardChanged = discardCount - lastDiscardCount > 0;

();

}

}

if (breakAfterAcquireFailure) {

从中这段代码中我们可以看到connectionErrorRetryAttempts值为1,timeBetweenConnectErrorMillis值为500,⽽

breakAfterAcquireFailure值为false,因此当我们数据源连接失败后,就会不断的进⾏重试连接,因此我对于对于该如何解决这样的问题

我们就有了答案:

1.若不想让重试,我们可以设置breakAfterAcquireFailure(true);connectionErrorRetryAttempts(0);