Use ConcurrentHashMap instead of HashMap
This commit is contained in:
parent
104e086bca
commit
123e2f546c
4 changed files with 8 additions and 8 deletions
|
|
@ -9,8 +9,8 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Reflection {
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ public class Reflection {
|
|||
|
||||
public Reflection(Class<?> clazz) {
|
||||
this.clazz = clazz;
|
||||
this.fieldMap = new HashMap<>();
|
||||
this.fieldMap = new ConcurrentHashMap<>();
|
||||
this.methodTree = new NamedReflectionCacheTree<>();
|
||||
this.constructorTree = new ReflectionCacheTree<>(null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package dev.frankheijden.minecraftreflection.cache;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class NamedReflectionCacheTree<T> {
|
||||
|
||||
private final Map<String, ReflectionCacheTree<T>> treeMap = new HashMap<>();
|
||||
private final Map<String, ReflectionCacheTree<T>> treeMap = new ConcurrentHashMap<>();
|
||||
|
||||
public T computeIfAbsent(String name, Class<?>[] parameters, Function<Class<?>[], ? extends T> mappingFunction) {
|
||||
return treeMap.computeIfAbsent(name, k -> new ReflectionCacheTree<>(null)).computeIfAbsent(parameters, mappingFunction);
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ package dev.frankheijden.minecraftreflection.cache;
|
|||
|
||||
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ReflectionCache {
|
||||
|
||||
private static final Map<Class<?>, MinecraftReflection> cachedReflections = new HashMap<>();
|
||||
private static final Map<Class<?>, MinecraftReflection> cachedReflections = new ConcurrentHashMap<>();
|
||||
|
||||
public static Map<Class<?>, MinecraftReflection> getCachedReflections() {
|
||||
return cachedReflections;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package dev.frankheijden.minecraftreflection.cache;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ public class ReflectionCacheTree<T> {
|
|||
public static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];
|
||||
|
||||
private T value;
|
||||
private final Map<Class<?>, ReflectionCacheTree<T>> children = new HashMap<>();
|
||||
private final Map<Class<?>, ReflectionCacheTree<T>> children = new ConcurrentHashMap<>();
|
||||
|
||||
public ReflectionCacheTree(T value) {
|
||||
this.value = value;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue