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 2022/04/07 03:57:05 UTC

[GitHub] [rocketmq] dugenkui03 commented on a diff in pull request #4094: [ISSUE #4090]Fail faster to keep consistent state

dugenkui03 commented on code in PR #4094:
URL: https://github.com/apache/rocketmq/pull/4094#discussion_r844625217


##########
client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultLitePullConsumerImpl.java:
##########
@@ -271,6 +271,14 @@ public synchronized boolean isRunning() {
         return this.serviceState == ServiceState.RUNNING;
     }
 
+    public synchronized boolean isCreateJust() {
+        return this.serviceState == ServiceState.CREATE_JUST;
+    }
+
+    public synchronized ServiceState getServiceState() {
+        return this.serviceState;
+    }
+

Review Comment:
   `serviceState` is in a  wrong/incompletable state before `synchronized #start()` return, since the value of `serviceState` is modified several times in `synchronized #start()`. `synchronized` in `isCreateJust` and `getServiceState` avoid read `wrong/incompletable` value.
   
   > `synchronized #start()`中对`serviceState`进行了多次更新、并且方法返回之前的状态是 不正确/不完整 的,`synchronized `是为了避免读取到这些 不正确/不完整 的状态。而且我注意到在该pr之前,`serviceState`的修改和读取也都使用了`synchronized`加锁、这已经可以保证`serviceState`的可见性了,因此`serviceState`上的`volatile`修饰符似乎是多余的。



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org