zoukankan      html  css  js  c++  java
  • Web项目ConcurrentModificationException异常

      后台SSH在做Session删除的时候,遇到了ConcurrentModificationException异常。

      参考资料:http://blog.csdn.net/idesvo/article/details/26558073

      问题代码:

    for (BorrowEquip borrowEquip : basketList) {
      if(borrowEquip.getEquipId() == idTest){
        basketList.remove(borrowEquip);
      }
    }
    

      更改后代码:

    for (BorrowEquip borrowEquip : basketList) {
      Iterator<BorrowEquip> iterator = basketList.iterator();
        if(borrowEquip.getEquipId() == idTest){
          iterator.next();
    	 iterator.remove();
    	 break;
    	}
    }
    

      删除方法的整个代码:

    public String deleteBasketEquip() {
      Long idTest = 1L;
    		
      Map<String, Object> basketMap = ActionContext.getContext().getSession();
    		
      List<BorrowEquip> basketList = new ArrayList<BorrowEquip>();
      basketList = (List<BorrowEquip>)basketMap.get("Basket");
    		
      for (BorrowEquip borrowEquip : basketList) {
        Iterator<BorrowEquip> iterator = basketList.iterator();     if(borrowEquip.getEquipId() == idTest){       iterator.next();  iterator.remove();  break;     }   }   return "success"; }

      

  • 相关阅读:
    [poj 1741]Tree 点分治
    [bzoj 3251]树上三角形
    [bzoj 3687]简单题 bitset的运用
    HDU [P5015] 233 Matrix
    POJ 3233
    洛谷 [P3629] 巡逻
    POJ 2728 Desert King
    洛谷 [P2886] 牛继电器Cow Relays
    POJ 1734 Sightseeing trip
    洛谷 [P3008] 道路与航线
  • 原文地址:https://www.cnblogs.com/overfly/p/7941647.html
Copyright © 2011-2022 走看看