`
bask
  • 浏览: 144630 次
  • 性别: Icon_minigender_1
  • 来自: 宇宙
社区版块
存档分类
最新评论

ConcurrentModificationException 的解决办法

阅读更多
1.出现 java.util.ConcurrentModificationException 时的解决办法
//(1) 根据某个id直接删除全部(如果数据库中的多对多关系)
Set<Largess> largessSet = promotion.getLargess();
largessSet.clear();
//或者
for(Iterator it = largessSet.iterator();it.hasNext();) {
	Largess largess = (Largess)it.next();
	it.remove();//先移除
	largessSet.remove(largess);
}
//(2) 根据某个条件删除 就是用Iterator
for(Iterator it = promotionList.iterator();it.hasNext();) {
	Promotion promotion = (Promotion)it.next();
	it.remove();//先移除
	if(promotion.getEndTime().before(new Date())) {
		xxxManager.remove(promotion);
		//TODO 其他处理
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics