Skip to content

Commit 6fb8993

Browse files
artembilanspring-builds
authored andcommitted
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 (cherry picked from commit adcfdfb)
1 parent d91d473 commit 6fb8993

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
@@ -412,13 +412,17 @@ public boolean acquire(String lock) {
412412
public boolean acquire(String lock, Duration ttlDuration) {
413413
return this.readCommittedTransactionTemplate.<Boolean>execute(
414414
transactionStatus -> {
415-
if (this.template.update(this.updateQuery, this.id, ttlEpochMillis(ttlDuration),
416-
this.region, lock, this.id, currentTime()) > 0) {
415+
LocalDateTime currentTime = currentTime();
416+
if (this.template.update(this.updateQuery, this.id, currentTime.plus(ttlDuration),
417+
this.region, lock, this.id, currentTime) > 0) {
418+
417419
return true;
418420
}
421+
419422
try {
423+
currentTime = currentTime();
420424
return this.template.update(this.insertQuery, this.region, lock, this.id,
421-
currentTime(), ttlEpochMillis(ttlDuration)) > 0;
425+
currentTime, currentTime.plus(ttlDuration)) > 0;
422426
}
423427
catch (DataIntegrityViolationException ex) {
424428
return false;

0 commit comments

Comments
 (0)