Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#1794 #2137
都提到过 Arthas 存在 stop 后,ArthasClassloader 无法回收的问题。
在 #2978 中排查的结论是 Arthas 的在退出时没有对 ThreadLocal 进行清理,ArthasClassloader加载的相关对象泄露在了业务线程的 Thread.threadlocals.table 中,最终导致 ArthasClassloader 无法被 gc 回收。
主要是
ThreadLocalWatch.timestampRef和ExpressFactory.expressRef两个 threadLocal 未清理导致:本 PR 的思路就是在 AdviceListener 的 destory 调用清空相关 ThreadLocal。因为 Java 的 ThreadLocal 不支持全部清空,只能清理当前线程,所以基于 ConcurrentHashMap 重新写了一个 CleanableThreadLocal 方便清理。