2021-01-21 18:54:39 [http-nio-7001-exec-33] WARN c.t.a.c.c.m.StackAdviceListener -stack failed.
java.lang.NullPointerException: null
at com.taobao.arthas.core.command.monitor200.StackAdviceListener.finishing(StackAdviceListener.java:67)
at com.taobao.arthas.core.command.monitor200.StackAdviceListener.afterReturning(StackAdviceListener.java:52)
at com.taobao.arthas.core.advisor.AdviceListenerAdapter.afterReturning(AdviceListenerAdapter.java:57)
at com.taobao.arthas.core.advisor.SpyImpl.atExit(SpyImpl.java:67)
at java.arthas.SpyAPI.atExit(SpyAPI.java:64)
原因是 com.taobao.arthas.core.command.monitor200.StackAdviceListener#stackThreadLocal
private final ThreadLocal<StackModel> stackThreadLocal = new ThreadLocal<StackModel>();
private void finishing(Advice advice) {
// 本次调用的耗时
try {
double cost = threadLocalWatch.costInMillis();
boolean conditionResult = isConditionMet(command.getConditionExpress(), advice, cost);
if (this.isVerbose()) {
process.write("Condition express: " + command.getConditionExpress() + " , result: " + conditionResult + "\n");
}
if (conditionResult) {
// TODO: concurrency issues for process.write
// TODO: should clear stackThreadLocal?
StackModel stackModel = stackThreadLocal.get();
stackModel.setTs(new Date());
process.appendResult(stackModel);
process.times().incrementAndGet();
if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) {
abortProcess(process, command.getNumberOfLimit());
}
}
stackThreadLocal 没有正确初始化,参考ThreadLocal的javadoc
stackThreadLocal里的对象被放到异步queue里了,会有并发问题