Skip to content

Commit 70acf1f

Browse files
committed
Use ConcurrentReferenceHashMap in favor of Collections.synchronizedMap(new WeakHashMap<>()) to improve performance
1 parent 2bbc133 commit 70acf1f

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 2.2.1
2+
* Use `ConcurrentReferenceHashMap` in favor of `Collections.synchronizedMap(new WeakHashMap<>())` to improve performance
3+
14
# 2.2.0
25
* Vaadin
36
* `SecureVaadinRequestCache` now uses `RequestUtil#isSecuredFlowRoute` which should be more performant and future-proof

oauth2-oidc-remember-me/src/main/java/software/xdev/sse/oauth2/rememberme/EnsureNonConcurrentExec.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
*/
1616
package software.xdev.sse.oauth2.rememberme;
1717

18-
import java.util.Collections;
1918
import java.util.Map;
20-
import java.util.WeakHashMap;
2119
import java.util.concurrent.ConcurrentHashMap;
2220
import java.util.concurrent.locks.Lock;
2321
import java.util.concurrent.locks.ReentrantLock;
2422
import java.util.function.Function;
2523

2624
import org.slf4j.Logger;
2725
import org.slf4j.LoggerFactory;
26+
import org.springframework.util.ConcurrentReferenceHashMap;
2827

2928

3029
/**
@@ -35,7 +34,8 @@ public class EnsureNonConcurrentExec<K, V>
3534
private static final Logger LOG = LoggerFactory.getLogger(EnsureNonConcurrentExec.class);
3635

3736
protected final Map<K, Lock> keyLocks = new ConcurrentHashMap<>();
38-
protected final Map<Lock, SavedResult<V>> lockResultsCache = Collections.synchronizedMap(new WeakHashMap<>());
37+
protected final Map<Lock, SavedResult<V>> lockResultsCache =
38+
new ConcurrentReferenceHashMap<>(32, ConcurrentReferenceHashMap.ReferenceType.WEAK);
3939

4040
protected final Function<RuntimeException, SavedResult<V>> onException;
4141

oauth2-oidc/src/main/java/software/xdev/sse/oauth2/checkauth/OAuth2AuthChecker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
3333
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
3434
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
35+
import org.springframework.util.ConcurrentReferenceHashMap;
3536

3637
import software.xdev.sse.oauth2.checkauth.disabledcheck.OAuth2IsDisabledChecker;
3738

@@ -58,7 +59,7 @@ public class OAuth2AuthChecker
5859
// https://docs.pmd-code.org/pmd-doc-7.5.0/pmd_rules_java_multithreading.html#avoidsynchronizedstatement
5960
// https://openjdk.org/jeps/8337395
6061
protected final Map<OAuth2AuthorizedClient, ReentrantLock> clientLocks =
61-
Collections.synchronizedMap(new WeakHashMap<>());
62+
new ConcurrentReferenceHashMap<>(32, ConcurrentReferenceHashMap.ReferenceType.WEAK);
6263

6364
public OAuth2AuthChecker(
6465
final OAuth2AuthorizedClientManager clientManager,

0 commit comments

Comments
 (0)