---
title: "ConcurrentModificationException  的解决办法"
author: "bask"
date: "2008-08-01T11:07:06Z"
tags: []
slug: "concurrentmodificationexception"
draft: false
lastmod: "2008-08-01T11:07:06Z"
id: 222676
url: "https://bask.iteye.com/blog/222676"
---

1.出现 java.util.ConcurrentModificationException 时的解决办法

```java

//(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 其他处理
	}
}
```