Skip to content

Commit d397020

Browse files
committed
create ConcurrentHashMap by CollectionUtils to avoid dead lock
1 parent 62b40b2 commit d397020

File tree

6 files changed

+14
-18
lines changed
  • dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance
  • dubbo-configcenter-extensions/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul
  • dubbo-metadata-report-extensions/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis
  • dubbo-registry-extensions/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul
  • dubbo-remoting-extensions/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/support
  • dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/utils

6 files changed

+14
-18
lines changed

dubbo-cluster-extensions/dubbo-cluster-loadbalance-peakewma/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/PeakEwmaLoadBalance.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.dubbo.rpc.cluster.loadbalance;
1818

1919
import org.apache.dubbo.common.URL;
20+
import org.apache.dubbo.common.utils.CollectionUtils;
2021
import org.apache.dubbo.rpc.Invocation;
2122
import org.apache.dubbo.rpc.Invoker;
2223
import org.apache.dubbo.rpc.RpcStatus;
@@ -25,8 +26,7 @@
2526

2627
import java.util.ArrayList;
2728
import java.util.List;
28-
import java.util.concurrent.ConcurrentHashMap;
29-
import java.util.concurrent.ConcurrentMap;
29+
import java.util.Map;
3030
import java.util.concurrent.ThreadLocalRandom;
3131
import java.util.concurrent.locks.ReentrantLock;
3232

@@ -62,7 +62,7 @@ public void setApplicationModel(ApplicationModel applicationModel) {
6262
decayTime = applicationModel.getModelEnvironment().getConfiguration().getInt(PEAK_EWMA_DECAY_TIME, 10_000);
6363
}
6464

65-
private ConcurrentMap<RpcStatus, Metric> methodMap = new ConcurrentHashMap<>();
65+
private Map<RpcStatus, Metric> methodMap = CollectionUtils.newConcurrentHashMap();
6666

6767
protected static class Metric {
6868
// last timestamp in Millis we observed an runningTime

dubbo-configcenter-extensions/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
import java.util.Map;
4242
import java.util.Optional;
4343
import java.util.Set;
44-
import java.util.concurrent.ConcurrentHashMap;
45-
import java.util.concurrent.ConcurrentMap;
4644

4745
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
4846

@@ -58,7 +56,7 @@ public class ConsulDynamicConfiguration extends TreePathDynamicConfiguration {
5856

5957
private final int watchTimeout;
6058

61-
private final ConcurrentMap<String, ConsulListener> watchers = new ConcurrentHashMap<>();
59+
private final Map<String, ConsulListener> watchers = CollectionUtils.newConcurrentHashMap();
6260

6361
public ConsulDynamicConfiguration(URL url) {
6462
super(url);

dubbo-metadata-report-extensions/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public MappingDataListener getMappingDataListener() {
456456
*/
457457
class NotifySub extends JedisPubSub {
458458

459-
private final Map<String, Set<MappingListener>> listeners = new ConcurrentHashMap<>();
459+
private final Map<String, Set<MappingListener>> listeners = CollectionUtils.newConcurrentHashMap();
460460

461461
public void addListener(String key, MappingListener listener) {
462462
Set<MappingListener> listenerSet = listeners.computeIfAbsent(key, k -> new ConcurrentHashSet<>());

dubbo-registry-extensions/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulRegistry.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import java.util.List;
4343
import java.util.Map;
4444
import java.util.Objects;
45-
import java.util.concurrent.ConcurrentHashMap;
46-
import java.util.concurrent.ConcurrentMap;
4745
import java.util.concurrent.ExecutorService;
4846
import java.util.concurrent.ScheduledExecutorService;
4947
import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -76,7 +74,7 @@ public class ConsulRegistry extends FailbackRegistry {
7674
private long checkPassInterval;
7775
private ExecutorService notifierExecutor = newCachedThreadPool(
7876
new NamedThreadFactory("dubbo-consul-notifier", true));
79-
private ConcurrentMap<URL, ConsulNotifier> notifiers = new ConcurrentHashMap<>();
77+
private Map<URL, ConsulNotifier> notifiers = CollectionUtils.newConcurrentHashMap();
8078
private ScheduledExecutorService ttlConsulCheckExecutor;
8179
/**
8280
* The ACL token

dubbo-remoting-extensions/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/support/AbstractEtcdClient.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.dubbo.common.URL;
3737
import org.apache.dubbo.common.logger.Logger;
3838
import org.apache.dubbo.common.logger.LoggerFactory;
39+
import org.apache.dubbo.common.utils.CollectionUtils;
3940
import org.apache.dubbo.common.utils.ConcurrentHashSet;
4041
import org.apache.dubbo.common.utils.StringUtils;
4142
import org.apache.dubbo.remoting.etcd.ChildListener;
@@ -44,9 +45,8 @@
4445

4546
import java.util.Arrays;
4647
import java.util.List;
48+
import java.util.Map;
4749
import java.util.Set;
48-
import java.util.concurrent.ConcurrentHashMap;
49-
import java.util.concurrent.ConcurrentMap;
5050

5151
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
5252
import static org.apache.dubbo.remoting.etcd.Constants.CONFIGURATORS_CATEGORY;
@@ -62,7 +62,7 @@ public abstract class AbstractEtcdClient<WatcherListener> implements EtcdClient
6262

6363
private final Set<StateListener> stateListeners = new ConcurrentHashSet<>();
6464

65-
private final ConcurrentMap<String, ConcurrentMap<ChildListener, WatcherListener>> childListeners = new ConcurrentHashMap<>();
65+
private final Map<String, Map<ChildListener, WatcherListener>> childListeners = CollectionUtils.newConcurrentHashMap();
6666
private final List<String> categories = Arrays.asList(PROVIDERS_CATEGORY, CONSUMERS_CATEGORY, ROUTERS_CATEGORY,
6767
CONFIGURATORS_CATEGORY);
6868
private volatile boolean closed = false;
@@ -106,14 +106,14 @@ public Set<StateListener> getSessionListeners() {
106106

107107
@Override
108108
public List<String> addChildListener(String path, final ChildListener listener) {
109-
ConcurrentMap<ChildListener, WatcherListener> listeners = childListeners.computeIfAbsent(path, k -> new ConcurrentHashMap<>());
109+
Map<ChildListener, WatcherListener> listeners = childListeners.computeIfAbsent(path, k -> CollectionUtils.newConcurrentHashMap());
110110
WatcherListener targetListener = listeners.computeIfAbsent(listener, k -> createChildWatcherListener(path, k));
111111
return addChildWatcherListener(path, targetListener);
112112
}
113113

114114
@Override
115115
public WatcherListener getChildListener(String path, ChildListener listener) {
116-
ConcurrentMap<ChildListener, WatcherListener> listeners = childListeners.get(path);
116+
Map<ChildListener, WatcherListener> listeners = childListeners.get(path);
117117
if (listeners == null) {
118118
return null;
119119
}
@@ -122,7 +122,7 @@ public WatcherListener getChildListener(String path, ChildListener listener) {
122122

123123
@Override
124124
public void removeChildListener(String path, ChildListener listener) {
125-
ConcurrentMap<ChildListener, WatcherListener> listeners = childListeners.get(path);
125+
Map<ChildListener, WatcherListener> listeners = childListeners.get(path);
126126
if (listeners != null) {
127127
WatcherListener targetListener = listeners.remove(listener);
128128
if (targetListener != null) {

dubbo-tag-extensions/dubbo-tag-subnets/src/main/java/org/apache/dubbo/tag/subnets/utils/SubnetUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.dubbo.tag.subnets.utils;
1818

19+
import org.apache.dubbo.common.utils.CollectionUtils;
1920
import org.apache.dubbo.common.utils.StringUtils;
2021

2122
import org.apache.commons.net.util.SubnetUtils;
@@ -26,14 +27,13 @@
2627
import java.util.ArrayList;
2728
import java.util.List;
2829
import java.util.Map;
29-
import java.util.concurrent.ConcurrentHashMap;
3030
import java.util.concurrent.locks.ReentrantReadWriteLock;
3131

3232

3333
public class SubnetUtil {
3434
public static final String TAG_SUBNETS_KEY = "tag.subnets";
3535

36-
private static final Map<String, List<SubnetUtils.SubnetInfo>> cellSubnets = new ConcurrentHashMap<>();
36+
private static final Map<String, List<SubnetUtils.SubnetInfo>> cellSubnets = CollectionUtils.newConcurrentHashMap();
3737
private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
3838
private static final ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
3939
private static final ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();

0 commit comments

Comments
 (0)