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:
parent
ff9c7141c5
commit
f9fe8efb2e
|
|
@ -20,7 +20,6 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -136,7 +135,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
@Nullable
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
private final Set<String> targetSourcedBeans = Collections.newSetFromMap(new ConcurrentHashMap<>(16));
|
||||
private final Set<String> targetSourcedBeans = ConcurrentHashMap.newKeySet(16);
|
||||
|
||||
private final Map<Object, Object> earlyBeanReferences = new ConcurrentHashMap<>(16);
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package org.springframework.context.event;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -82,7 +81,7 @@ public class EventListenerMethodProcessor
|
|||
@Nullable
|
||||
private final EventExpressionEvaluator evaluator;
|
||||
|
||||
private final Set<Class<?>> nonAnnotatedClasses = Collections.newSetFromMap(new ConcurrentHashMap<>(64));
|
||||
private final Set<Class<?>> nonAnnotatedClasses = ConcurrentHashMap.newKeySet(64);
|
||||
|
||||
|
||||
public EventListenerMethodProcessor() {
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
|||
|
||||
void stopForRestart() {
|
||||
if (this.running) {
|
||||
this.stoppedBeans = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
this.stoppedBeans = ConcurrentHashMap.newKeySet();
|
||||
stopBeans();
|
||||
this.running = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import java.lang.reflect.Method;
|
|||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -149,7 +148,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
|||
@Nullable
|
||||
private TaskSchedulerRouter localScheduler;
|
||||
|
||||
private final Set<Class<?>> nonAnnotatedClasses = Collections.newSetFromMap(new ConcurrentHashMap<>(64));
|
||||
private final Set<Class<?>> nonAnnotatedClasses = ConcurrentHashMap.newKeySet(64);
|
||||
|
||||
private final Map<Object, Set<ScheduledTask>> scheduledTasks = new IdentityHashMap<>(16);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.springframework.core;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
|
@ -39,9 +38,9 @@ public abstract class DecoratingClassLoader extends ClassLoader {
|
|||
}
|
||||
|
||||
|
||||
private final Set<String> excludedPackages = Collections.newSetFromMap(new ConcurrentHashMap<>(8));
|
||||
private final Set<String> excludedPackages = ConcurrentHashMap.newKeySet(8);
|
||||
|
||||
private final Set<String> excludedClasses = Collections.newSetFromMap(new ConcurrentHashMap<>(8));
|
||||
private final Set<String> excludedClasses = ConcurrentHashMap.newKeySet(8);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.core.task;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -183,7 +182,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
|
|||
public void setTaskTerminationTimeout(long timeout) {
|
||||
Assert.isTrue(timeout >= 0, "Timeout value must be >=0");
|
||||
this.taskTerminationTimeout = timeout;
|
||||
this.activeThreads = (timeout > 0 ? Collections.newSetFromMap(new ConcurrentHashMap<>()) : null);
|
||||
this.activeThreads = (timeout > 0 ? ConcurrentHashMap.newKeySet() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class SessionAttributesHandler {
|
|||
|
||||
private final Set<Class<?>> attributeTypes = new HashSet<>();
|
||||
|
||||
private final Set<String> knownAttributeNames = Collections.newSetFromMap(new ConcurrentHashMap<>(4));
|
||||
private final Set<String> knownAttributeNames = ConcurrentHashMap.newKeySet(4);
|
||||
|
||||
private final SessionAttributeStore sessionAttributeStore;
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class SessionAttributesHandler {
|
|||
|
||||
private final Set<Class<?>> attributeTypes = new HashSet<>();
|
||||
|
||||
private final Set<String> knownAttributeNames = Collections.newSetFromMap(new ConcurrentHashMap<>(4));
|
||||
private final Set<String> knownAttributeNames = ConcurrentHashMap.newKeySet(4);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue