Improve concurrency of Loader
@@ -7,13 +7,15 @@ import org.aion.types.AionAddress;
import java.io.IOException;
import java.lang.ref.SoftReference;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
public class Loader {
private static final int MAX_ENTRY = 256;
- private LinkedHashMap<AionAddress, SoftReference<LoadedDApp>> dappCache= new LinkedHashMap<>(
+ private Map<AionAddress, SoftReference<LoadedDApp>> dappCache = Collections.synchronizedMap(
+ new LinkedHashMap<>(
MAX_ENTRY + 1,
1.0f,
true
@@ -21,10 +23,9 @@ public class Loader {
protected boolean removeEldestEntry(Map.Entry entry) {
return (size() > MAX_ENTRY);
}
- };
+ });
public LoadedDApp load(AionAddress addr, IExternalState es, boolean preserveDebuggability) throws IOException {
- synchronized(this) {
var dappSR = dappCache.get(addr);
var dapp = (dappSR != null) ? dappSR.get() : null;
if (dapp == null) {
@@ -39,4 +40,3 @@ public class Loader {
return dapp;
}
}
-}
