You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2018/09/21 11:00:56 UTC

[GitHub] dongeforever commented on a change in pull request #470: Upgrade JDK dependency and code clean based on the features of JDK 1.8

dongeforever commented on a change in pull request #470: Upgrade JDK dependency and code clean based on the features of JDK 1.8
URL: https://github.com/apache/rocketmq/pull/470#discussion_r219459565
 
 

 ##########
 File path: broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java
 ##########
 @@ -221,39 +222,23 @@ public TopicConfig createTopicInSendMessageBackMethod(
         final int clientDefaultTopicQueueNums,
         final int perm,
         final int topicSysFlag) {
-        TopicConfig topicConfig = this.topicConfigTable.get(topic);
-        if (topicConfig != null)
-            return topicConfig;
-
-        boolean createNew = false;
-
-        try {
-            if (this.lockTopicConfigTable.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
-                try {
-                    topicConfig = this.topicConfigTable.get(topic);
-                    if (topicConfig != null)
-                        return topicConfig;
-
-                    topicConfig = new TopicConfig(topic);
-                    topicConfig.setReadQueueNums(clientDefaultTopicQueueNums);
-                    topicConfig.setWriteQueueNums(clientDefaultTopicQueueNums);
-                    topicConfig.setPerm(perm);
-                    topicConfig.setTopicSysFlag(topicSysFlag);
-
-                    log.info("create new topic {}", topicConfig);
-                    this.topicConfigTable.put(topic, topicConfig);
-                    createNew = true;
-                    this.dataVersion.nextVersion();
-                    this.persist();
-                } finally {
-                    this.lockTopicConfigTable.unlock();
-                }
-            }
-        } catch (InterruptedException e) {
-            log.error("createTopicInSendMessageBackMethod exception", e);
-        }
-
-        if (createNew) {
+        // Internal class requires final variables
+        final AtomicBoolean createNew = new AtomicBoolean(false);
+        TopicConfig topicConfig = this.topicConfigTable.computeIfAbsent(topic, key -> {
 
 Review comment:
   @ConeyLiu why you polish createTopicInSendMessageBackMethod and skip createTopicInSendMessageMethod? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services