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

@@ -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);
/**

View File

@@ -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);
}
/**