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

解决abortProcess的并发问题 #2957

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

trytocatch
Copy link

AbstractTraceAdviceListener的102行有一个todo,此pr解决该问题
// TODO: concurrency issue to abort process

abortProcess可能会重复执行,表现形式为重复输出“Command execution times exceed limit..."

该问题可以直接利用AtomicInteger的原子性来解决,在自增时同时获取自增后的当前值(原子操作),并以该值作为判定依据,该值会递增且连续,那么只须判断该值是否与limit相等,便可保证有且只有一个线程调用abortProcess

原来使用AtomicInteger.get,无法保证连续(比如当前值为9,两个线程同时执行incrementAndGet,然后再同时执行get,两个线程获取到的值均为11,10这个数值便被跳过了),因而只能用大于等于来判定,从而导致并发时,可能多个线程同时满足条件

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

Successfully merging this pull request may close these issues.

1 participant