DerekYRC/mini-spring

多个bean需要回调销毁方法,在for循环remove

NotGiveUp opened this issue · 6 comments

@NotGiveUp 问题是?

在for循环里 remove报错 java.util.ConcurrentModificationException

@NotGiveUp 很奇怪,这么写理论上没有问题,日志能贴一下吗

你搞2个bean 实现DisposableBean 跑你的test 就行;

java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1442)
at java.util.HashMap$KeyIterator.next(HashMap.java:1466)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:76)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:190)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:186)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:168)
at org.springframework.test.ioc.CircularReferenceWithProxyBeanTest.testCircularReference(CircularReferenceWithProxyBeanTest.java:23)

@NotGiveUp get,beanNames指向disposableBeans.keySet()。有兴趣可以参考spring的做法提个pull request。
image

今晚修复下