drpmma commented on code in PR #6832:
URL: https://github.com/apache/rocketmq/pull/6832#discussion_r1217384716
##########
broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java:
##########
@@ -161,24 +161,15 @@ public synchronized boolean doChannelCloseEvent(final
String remoteAddr, final C
}
public synchronized void registerProducer(final String group, final
ClientChannelInfo clientChannelInfo) {
- ClientChannelInfo clientChannelInfoFound = null;
-
+ this.groupChannelTable.putIfAbsent(group, new ConcurrentHashMap<>());
ConcurrentHashMap<Channel, ClientChannelInfo> channelTable =
this.groupChannelTable.get(group);
- if (null == channelTable) {
- channelTable = new ConcurrentHashMap<>();
- this.groupChannelTable.put(group, channelTable);
- }
- clientChannelInfoFound =
channelTable.get(clientChannelInfo.getChannel());
+ ClientChannelInfo clientChannelInfoFound =
channelTable.putIfAbsent(clientChannelInfo.getChannel(), clientChannelInfo);
Review Comment:
It's recommended to use computeIfAbsent rather than if else.
##########
broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java:
##########
@@ -161,24 +161,15 @@ public synchronized boolean doChannelCloseEvent(final
String remoteAddr, final C
}
public synchronized void registerProducer(final String group, final
ClientChannelInfo clientChannelInfo) {
- ClientChannelInfo clientChannelInfoFound = null;
-
+ this.groupChannelTable.putIfAbsent(group, new ConcurrentHashMap<>());
ConcurrentHashMap<Channel, ClientChannelInfo> channelTable =
this.groupChannelTable.get(group);
Review Comment:
Why not use the return value of putIfAbsent?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]