Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AtomicLong.updateAndGet()超级费CPU,并发一多就100% #86

Open
yangxuanjia opened this issue Mar 3, 2023 · 1 comment
Open

AtomicLong.updateAndGet()超级费CPU,并发一多就100% #86

yangxuanjia opened this issue Mar 3, 2023 · 1 comment

Comments

@yangxuanjia
Copy link

yangxuanjia commented Mar 3, 2023

Screenshot from 2023-03-03 15-26-20
Screenshot from 2023-03-03 15-27-17

原来:

// 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();
}
@zxy1994
Copy link

zxy1994 commented Apr 4, 2023

Screenshot from 2023-03-03 15-26-20 Screenshot from 2023-03-03 15-27-17

原来:

// 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();
}

您好,请问下你这个是什么工具?看起来很直观,谢谢大佬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants