We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
java.arthas.SpyAPI.atEnter 可能抛出 ConcurrentModificationException 。版本 3.6.5
The text was updated successfully, but these errors were encountered:
这里看起来是注册AdviceListener和迭代访问多线程出发导致的,大佬有什么解决的思路么? 我的想法是: 1、使用 CopyOnWriteArrayList,适合读多写少 2、使用显示的lock进行线程同步
Sorry, something went wrong.
我觉得CopyOnWriteArrayList是个不错的办法,修改是很低频的操作,主要还是在方法调用的时候,读这个list
另外,相应的还发现个问题,像AdviceListenerManager#registerTraceAdviceListener,没有被synchronized(this)保护
public void registerTraceAdviceListener(String className, String owner, String methodName, String methodDesc, AdviceListener listener) { className = className.replace('/', '.'); String key = keyForTrace(className, owner, methodName, methodDesc); List<AdviceListener> listeners = map.get(key); if (listeners == null) { listeners = new ArrayList<AdviceListener>(); map.put(key, listeners); } if (!listeners.contains(listener)) { listeners.add(listener); } }
其它修改该List的地方基本都加了锁,不知道这里是不是疏忽了?如果没有锁保护的话,这里的map.put也是存在并发问题的。 假如两个线程都执行到这里,都new了一个ArrayList来添加AdviceListener,然后两个线程都执行put操作,那么先put的List便被替换掉了,然后继续往此List添加AdviceListener便无意义了,便丢失了,这里可以使用putIfAbsent,或computeIfAbsent来保证原子性,类似的map操作还有十来处,个别的有锁保护,有没则没有
看要不要我按此思路来修复一下 @hengyunabc
No branches or pull requests
java.arthas.SpyAPI.atEnter 可能抛出 ConcurrentModificationException 。版本 3.6.5
The text was updated successfully, but these errors were encountered: