Use ConcurrentHashMap.newKeySet

In places where a ConcurrentHashMap was used as a set by wrapping it
with Collections.newSetFromMap, switch to just using the set returned
by ConcurrentHashMap.newKeySet directly.

Closes gh-32294
This commit is contained in:
Patrick Strawderman
2024-02-19 08:57:33 -08:00
committed by Sam Brannen
parent ff9c7141c5
commit f9fe8efb2e
14 changed files with 16 additions and 29 deletions

View File

@@ -23,7 +23,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -88,7 +87,7 @@ public final class CachedIntrospectionResults {
* accept classes from, even if the classes do not qualify as cache-safe.
*/
static final Set<ClassLoader> acceptedClassLoaders =
Collections.newSetFromMap(new ConcurrentHashMap<>(16));
ConcurrentHashMap.newKeySet(16);
/**
* Map keyed by Class containing CachedIntrospectionResults, strongly held.

View File

@@ -29,7 +29,6 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
@@ -178,7 +177,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
@Nullable
private MetadataReaderFactory metadataReaderFactory;
private final Set<String> lookupMethodsChecked = Collections.newSetFromMap(new ConcurrentHashMap<>(256));
private final Set<String> lookupMethodsChecked = ConcurrentHashMap.newKeySet(256);
private final Map<Class<?>, Constructor<?>[]> candidateConstructorsCache = new ConcurrentHashMap<>(256);

View File

@@ -16,7 +16,6 @@
package org.springframework.beans.factory.config;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Set;
@@ -77,7 +76,7 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer {
/**
* Contains names of beans that have overrides.
*/
private final Set<String> beanNames = Collections.newSetFromMap(new ConcurrentHashMap<>(16));
private final Set<String> beanNames = ConcurrentHashMap.newKeySet(16);
/**

View File

@@ -20,7 +20,6 @@ import java.beans.PropertyEditor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -165,7 +164,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
private final Map<String, RootBeanDefinition> mergedBeanDefinitions = new ConcurrentHashMap<>(256);
/** Names of beans that have already been created at least once. */
private final Set<String> alreadyCreated = Collections.newSetFromMap(new ConcurrentHashMap<>(256));
private final Set<String> alreadyCreated = ConcurrentHashMap.newKeySet(256);
/** Names of beans that are currently in creation. */
private final ThreadLocal<Object> prototypesCurrentlyInCreation =

View File

@@ -29,7 +29,6 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.IdentityHashMap;
import java.util.Iterator;
@@ -169,7 +168,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
private final Map<String, BeanDefinitionHolder> mergedBeanDefinitionHolders = new ConcurrentHashMap<>(256);
// Set of bean definition names with a primary marker. */
private final Set<String> primaryBeanNames = Collections.newSetFromMap(new ConcurrentHashMap<>(16));
private final Set<String> primaryBeanNames = ConcurrentHashMap.newKeySet(16);
/** Map of singleton and non-singleton bean names, keyed by dependency type. */
private final Map<Class<?>, String[]> allBeanNamesByType = new ConcurrentHashMap<>(64);

View File

@@ -16,7 +16,6 @@
package org.springframework.beans.factory.support;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -91,12 +90,10 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
private final Lock singletonLock = new ReentrantLock();
/** Names of beans that are currently in creation. */
private final Set<String> singletonsCurrentlyInCreation =
Collections.newSetFromMap(new ConcurrentHashMap<>(16));
private final Set<String> singletonsCurrentlyInCreation = ConcurrentHashMap.newKeySet(16);
/** Names of beans currently excluded from in creation checks. */
private final Set<String> inCreationCheckExclusions =
Collections.newSetFromMap(new ConcurrentHashMap<>(16));
private final Set<String> inCreationCheckExclusions = ConcurrentHashMap.newKeySet(16);
@Nullable
private volatile Thread singletonCreationThread;