From b4153618a414f43d12feb2b33487fa1a35be4674 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 13 Feb 2024 11:07:20 +0100 Subject: [PATCH] Consistent Lock field declaration (instead of ReentrantLock field type) --- .../support/ReloadableResourceBundleMessageSource.java | 3 ++- .../scheduling/concurrent/ExecutorLifecycleDelegate.java | 3 ++- .../web/server/session/InMemoryWebSessionStore.java | 7 +++---- .../web/socket/messaging/SubProtocolWebSocketHandler.java | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java index f4eb4d6e59..3acaa03808 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.springframework.context.ResourceLoaderAware; @@ -650,7 +651,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased private volatile long refreshTimestamp = -2; - private final ReentrantLock refreshLock = new ReentrantLock(); + private final Lock refreshLock = new ReentrantLock(); /** Cache to hold already generated MessageFormats per message code. */ private final ConcurrentMap> cachedMessageFormats = diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorLifecycleDelegate.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorLifecycleDelegate.java index 80b78ce314..e8e705fc21 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorLifecycleDelegate.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorLifecycleDelegate.java @@ -18,6 +18,7 @@ package org.springframework.scheduling.concurrent; import java.util.concurrent.ExecutorService; import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.springframework.context.SmartLifecycle; @@ -36,7 +37,7 @@ final class ExecutorLifecycleDelegate implements SmartLifecycle { private final ExecutorService executor; - private final ReentrantLock pauseLock = new ReentrantLock(); + private final Lock pauseLock = new ReentrantLock(); private final Condition unpaused = this.pauseLock.newCondition(); diff --git a/spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java b/spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java index 504ee546d3..ecc1557d6a 100644 --- a/spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java +++ b/spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import java.util.Iterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import reactor.core.publisher.Mono; @@ -315,12 +316,10 @@ public class InMemoryWebSessionStore implements WebSessionStore { /** Max time between expiration checks. */ private static final int CHECK_PERIOD = 60 * 1000; - - private final ReentrantLock lock = new ReentrantLock(); + private final Lock lock = new ReentrantLock(); private Instant checkTime = clock.instant().plus(CHECK_PERIOD, ChronoUnit.MILLIS); - public void checkIfNecessary(Instant now) { if (this.checkTime.isBefore(now)) { removeExpiredSessions(now); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java index 577408d635..d93970ea29 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.apache.commons.logging.Log; @@ -98,7 +99,7 @@ public class SubProtocolWebSocketHandler private volatile long lastSessionCheckTime = System.currentTimeMillis(); - private final ReentrantLock sessionCheckLock = new ReentrantLock(); + private final Lock sessionCheckLock = new ReentrantLock(); private final DefaultStats stats = new DefaultStats();