7311: Use ConcurrentHashMap in DefaultPeerSelector

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
pull/7628/head
Matilda Clerke 2 months ago
parent 38f04ab5a1
commit 6de3fb366a
  1. 5
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerSelector.java

@ -22,6 +22,7 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -34,9 +35,7 @@ import org.slf4j.LoggerFactory;
public class DefaultPeerSelector implements PeerSelector { public class DefaultPeerSelector implements PeerSelector {
private static final Logger LOG = LoggerFactory.getLogger(DefaultPeerSelector.class); private static final Logger LOG = LoggerFactory.getLogger(DefaultPeerSelector.class);
// use a synchronized map to ensure the map is never modified by multiple threads at once private final Map<PeerId, EthPeer> ethPeersByPeerId = new ConcurrentHashMap<>();
private final Map<PeerId, EthPeer> ethPeersByPeerId =
Collections.synchronizedMap(new HashMap<>());
/** /**
* Gets the highest reputation peer matching the supplied filter * Gets the highest reputation peer matching the supplied filter

Loading…
Cancel
Save