Skip to content

Commit adcfdfb

Browse files
committed
DefaultLockRepository: optimize time use in the acquire()
Related to: #10906 Currently, the `currentTime()` is used twice in the same query: for `currentTime` and `ttl` query params. * Extract `currentTime` into local variable and use it for the `ttl` query param. * Calculate `currentTime` for a second update query: the time might pass since the previous update query call **Auto-cherry-pick to `7.0.x`**
1 parent 445fbcb commit adcfdfb

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/DefaultLockRepository.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,17 @@ public boolean delete(String lock) {
389389
public boolean acquire(String lock, Duration ttlDuration) {
390390
return this.readCommittedTransactionTemplate.<Boolean>execute(
391391
transactionStatus -> {
392-
if (this.template.update(this.updateQuery, this.id, ttlEpochMillis(ttlDuration),
393-
this.region, lock, this.id, currentTime()) > 0) {
392+
LocalDateTime currentTime = currentTime();
393+
if (this.template.update(this.updateQuery, this.id, currentTime.plus(ttlDuration),
394+
this.region, lock, this.id, currentTime) > 0) {
395+
394396
return true;
395397
}
398+
396399
try {
400+
currentTime = currentTime();
397401
return this.template.update(this.insertQuery, this.region, lock, this.id,
398-
currentTime(), ttlEpochMillis(ttlDuration)) > 0;
402+
currentTime, currentTime.plus(ttlDuration)) > 0;
399403
}
400404
catch (DataIntegrityViolationException ex) {
401405
return false;

0 commit comments

Comments
 (0)