java.util.ConcurrentModificationException: null
at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1207)
at java.util.TreeMap$KeyIterator.next(TreeMap.java:1261)
at org.jeasy.rules.core.RuleProxy.appendActionMethodsNames(RuleProxy.java:353)
at org.jeasy.rules.core.RuleProxy.getRuleDescription(RuleProxy.java:334)
at org.jeasy.rules.core.RuleProxy.invoke(RuleProxy.java:101)
at com.sun.proxy.$Proxy160.getDescription(Unknown Source)
at org.jeasy.rules.core.DefaultRulesEngine.log(DefaultRulesEngine.java:146)
at org.jeasy.rules.core.DefaultRulesEngine.doFire(DefaultRulesEngine.java:80)
at org.jeasy.rules.core.DefaultRulesEngine.fire(DefaultRulesEngine.java:70)
private Set getActionMethodBeans() {
if (this.actionMethods == null) {
this.actionMethods = new TreeSet<>();
Method[] methods = getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(Action.class)) {
Action actionAnnotation = method.getAnnotation(Action.class);
int order = actionAnnotation.order();
this.actionMethods.add(new ActionMethodOrderBean(method, order));
}
}
}
return this.actionMethods;
}
java.util.ConcurrentModificationException: null at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1207) at java.util.TreeMap$KeyIterator.next(TreeMap.java:1261) at org.jeasy.rules.core.RuleProxy.appendActionMethodsNames(RuleProxy.java:353) at org.jeasy.rules.core.RuleProxy.getRuleDescription(RuleProxy.java:334) at org.jeasy.rules.core.RuleProxy.invoke(RuleProxy.java:101) at com.sun.proxy.$Proxy160.getDescription(Unknown Source) at org.jeasy.rules.core.DefaultRulesEngine.log(DefaultRulesEngine.java:146) at org.jeasy.rules.core.DefaultRulesEngine.doFire(DefaultRulesEngine.java:80) at org.jeasy.rules.core.DefaultRulesEngine.fire(DefaultRulesEngine.java:70)
private Set getActionMethodBeans() {
if (this.actionMethods == null) {
this.actionMethods = new TreeSet<>();
Method[] methods = getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(Action.class)) {
Action actionAnnotation = method.getAnnotation(Action.class);
int order = actionAnnotation.order();
this.actionMethods.add(new ActionMethodOrderBean(method, order));
}
}
}
return this.actionMethods;
}
内部actionMethods对象是TreeSet非线程安全,多线程并发时,遍历时会抛出ConcurrentModificationException
解决思路: