Skip to content

Commit

Permalink
refactor: update type
Browse files Browse the repository at this point in the history
* Now that the variable is protected by a Mutex, it doesn't need to be
  inside an `Atomic` anymore.
  • Loading branch information
bruce-ricard committed May 25, 2023
1 parent 4b12107 commit 463a3c5
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class UaaTokenStore implements AuthorizationCodeServices {
private final RandomValueStringGenerator generator = new RandomValueStringGenerator(32);
private final RowMapper rowMapper = new TokenCodeRowMapper();

private AtomicReference<Instant> lastClean = new AtomicReference<>(Instant.EPOCH);
private Instant lastClean = Instant.EPOCH;
private Semaphore cleanMutex = new Semaphore(1);

public UaaTokenStore(DataSource dataSource) {
Expand Down Expand Up @@ -214,14 +214,12 @@ else if (map.get(USER_AUTHENTICATION_UAA_PRINCIPAL)!=null) {

protected void performExpirationCleanIfEnoughTimeHasElapsed() {
if (cleanMutex.tryAcquire()) {
Instant last = lastClean.get();
//check if we should expire again
Instant now = Instant.now();
if (enoughTimeHasPassedSinceLastExpirationClean(last, now)) {
if (enoughTimeHasPassedSinceLastExpirationClean(lastClean, now)) {
//avoid concurrent deletes from the same UAA - performance improvement
if (lastClean.compareAndSet(last, now)) {
actuallyPerformExpirationClean(now);
}
lastClean = now;
actuallyPerformExpirationClean(now);
}
cleanMutex.release();
}
Expand Down

0 comments on commit 463a3c5

Please sign in to comment.