mirror of https://github.com/apache/activemq.git
AMQ-7403: Potential PreparedStatement/ResultSet leak in LeaseDatabaseLocker#determineTimeDifference
This commit is contained in:
parent
6417d62f60
commit
26a0f8214c
|
@ -133,19 +133,20 @@ public class LeaseDatabaseLocker extends AbstractJDBCLocker {
|
|||
}
|
||||
|
||||
protected long determineTimeDifference(Connection connection) throws SQLException {
|
||||
PreparedStatement statement = connection.prepareStatement(getStatements().getCurrentDateTime());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
long result = 0l;
|
||||
if (resultSet.next()) {
|
||||
Timestamp timestamp = resultSet.getTimestamp(1);
|
||||
long diff = System.currentTimeMillis() - timestamp.getTime();
|
||||
if (Math.abs(diff) > maxAllowableDiffFromDBTime) {
|
||||
// off by more than maxAllowableDiffFromDBTime so lets adjust
|
||||
result = (-diff);
|
||||
try (PreparedStatement statement = connection.prepareStatement(getStatements().getCurrentDateTime());
|
||||
ResultSet resultSet = statement.executeQuery()) {
|
||||
long result = 0l;
|
||||
if (resultSet.next()) {
|
||||
Timestamp timestamp = resultSet.getTimestamp(1);
|
||||
long diff = System.currentTimeMillis() - timestamp.getTime();
|
||||
if (Math.abs(diff) > maxAllowableDiffFromDBTime) {
|
||||
// off by more than maxAllowableDiffFromDBTime so lets adjust
|
||||
result = (-diff);
|
||||
}
|
||||
LOG.info(getLeaseHolderId() + " diff adjust from db: " + result + ", db time: " + timestamp);
|
||||
}
|
||||
LOG.info(getLeaseHolderId() + " diff adjust from db: " + result + ", db time: " + timestamp);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void doStop(ServiceStopper stopper) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue