作者n3oanderson (wake up ...)
看板java
标题Re: [虫?]ConcurrentModificationException
时间Sun Jul 8 16:58:23 2012
ArrayList is fail-fast. In the scenario where one thread is acessing
to the list whilst the other is trying to do modification,
ConcurrentModificationException will be thrown. Applying
Collection.synchronizedXXXX()
or concurrent package can solve this problem.
http://www.ibm.com/developerworks/java/library/j-jtp07233/index.html
※ 引述《stupid5566 (屎丢比5566)》之铭言:
: public class ComicService {
: private Collection<ComicModel> models = new ArrayList<ComicModel>();
: public void delete(String isbnCode){
: for (ComicModel model : models){
: if(model.getIsbnCode().equals(isbnCode)){
: models.remove(model);
: }
: }
: }
: }
: 主程式:
: public class ComicApp {
: public static void main(String[] args) {
: ComicService comicService = new ComicService();
: comicService.delete("003");
: }
: }
: 结果跳出 java.util.ConcurrentModificationException 错误
: Model里面就是简单的getIsbnCode() setIsbnCode()
: 学长写得一模一样 但是可以成功删除
: 出了什麽问题吗
: 啾啾啾啾啾啾我!!!!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.168.73.251