99import com .taobao .arthas .core .util .LogUtil ;
1010import com .taobao .arthas .core .util .ThreadLocalWatch ;
1111
12+ import java .util .concurrent .atomic .AtomicBoolean ;
13+
1214/**
1315 * @author ralf0131 2017-01-06 16:02.
1416 */
@@ -17,6 +19,7 @@ public class AbstractTraceAdviceListener extends AdviceListenerAdapter {
1719 protected final ThreadLocalWatch threadLocalWatch = new ThreadLocalWatch ();
1820 protected TraceCommand command ;
1921 protected CommandProcess process ;
22+ private final AtomicBoolean processAborted = new AtomicBoolean (false );
2023
2124 protected final ThreadLocal <TraceEntity > threadBoundEntity = new ThreadLocal <TraceEntity >();
2225
@@ -99,7 +102,6 @@ private void finishing(ClassLoader loader, Advice advice) {
99102
100103 // 是否到达数量限制
101104 if (isLimitExceeded (command .getNumberOfLimit (), process .times ().get ())) {
102- // TODO: concurrency issue to abort process
103105 abortProcess (process , command .getNumberOfLimit ());
104106 }
105107 }
@@ -112,4 +114,12 @@ private void finishing(ClassLoader loader, Advice advice) {
112114 }
113115 }
114116 }
117+
118+ @ Override
119+ protected void abortProcess (CommandProcess process , int limit ) {
120+ // Only proceed if this thread is the first one to set the flag to true
121+ if (processAborted .compareAndSet (false , true )) {
122+ super .abortProcess (process , limit );
123+ }
124+ }
115125}
0 commit comments