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/12 10:48:09 UTC

[GitHub] [rocketmq] lwclover commented on pull request #4138: `RemotingCommand` is not thread-safe

lwclover commented on PR #4138:
URL: https://github.com/apache/rocketmq/pull/4138#issuecomment-1096562505

   > > Why not use ConcurrentHashMap instead of HashMap?Using ConcurrentHashMap, no need to lock when reading, and the scope of locking is smaller when writing.
   > 
   > That's my opinion: Do as little as possible to fix mistakes.
   > 
   > # describe in Chinese
   > 我习惯做尽可能少的事情去修正bug,尽量不去破坏原有的设计。
   > 
   > 这里使用`synchronized`的原因也许是jvm对`synchronized`加锁进行了优化:如果加锁代码块没有真实的发生多线程并发访问,则永远不会真正的加锁。我简单跟踪了下代码,应该是这个原因。 <img alt="image" width="1177" src="https://user-images.githubusercontent.com/18216266/162627024-8459f20e-ec9c-4e75-bac4-da0c5140ab8d.png">
   
   You were right. Synchronized has a lock upgrade process,Biased locks -> Lightweight locks -> Heavyweight locks.


-- 
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