AtomicLong.updateAndGet()超级费CPU,并发一多就100%
- Dominant language
- Java
- Stars
- 5.6k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description


原来:
```
// spin get next available cursor
long currentCursor = cursor.get();
long nextCursor = cursor.updateAndGet(old -> old == tail.get() ? old : old + 1);
// trigger padding in an async-mode if reach the threshold
long currentTail = tail.get();
```
改成下面这样是否可以???
```
// spin get next available cursor
long currentCursor = cursor.get();
long currentTail = tail.get();
long nextCursor = currentCursor;
if (currentCursor != currentTail) {
nextCursor = cursor.incrementAndGet();
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start from the cursor updateAndGet() path shown in the issue and examine its behavior as concurrency increases. Compare the proposed get/increment sequence with the existing atomic update under contention, checking cursor and tail correctness as well as CPU usage. Done means the chosen approach is validated for concurrent behavior and the reported CPU problem is addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100