-
Notifications
You must be signed in to change notification settings - Fork 371
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
add desensitization extension #433
Conversation
* 封装一个定时重置的计数器用于降低某些非必要操作的频率(比如某些预期内的错误日志). | ||
* 具有如下特征: | ||
* <ul> | ||
* <li>计数器的值永远不超过times</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment cloud be English
Codecov Report
@@ Coverage Diff @@
## master #433 +/- ##
============================================
- Coverage 44.78% 44.47% -0.32%
+ Complexity 224 219 -5
============================================
Files 287 289 +2
Lines 9480 9539 +59
Branches 936 947 +11
============================================
- Hits 4246 4242 -4
- Misses 4754 4811 +57
- Partials 480 486 +6 Continue to review full report at Codecov.
|
|
||
final AtomicInteger counter = new AtomicInteger(); | ||
long start = System.currentTimeMillis(); | ||
// 在 1000ms 和 2000ms 时刻 会重置 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
while (true) { | ||
int c = counter.get(); | ||
if (c < times) { | ||
if (counter.compareAndSet(c, c + 1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When can‘t get the CAS lock would be retry ,why not return false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like
- java.util.concurrent.atomic.AtomicInteger#getAndIncrement
- sun.misc.Unsafe#getAndAddInt
Every time, at least one thread will success.
cfbc5b5
to
0c62634
Compare
79c601e
to
f123d94
Compare
c1713dc
to
041b786
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Motivation:
data security
Modification:
add desensitization extension
Result: