Github user Jaskey commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/61
@lizhanhui
Acutully , if thread numbers are large , the cpu problem should be obvious
without doubt in a spin lock with `while(true)` without `sleep`.
But I also agree that we can create a blog for this, remove the comment for
me is fine , just DO NOT merge that commit.
Actully , my very first advice is that when implementing the spin lock add
`sleep(1)` when continiously fail to abatain the lock say 100 times, which
should solve most of the problems.
@Override
public void lock() {
int tryTimes = 0;
boolean flag;
do {
if (tryTimes++ % 100 ==0 ){
Thread.sleep(1); //fierce race condition
}
flag = this.putMessageSpinLock.compareAndSet(true, false);
}
while (!flag);
}
What's your advice
@zhouxinyu @vongosling @lizhanhui
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---