Sunday, 15 March 2015

exception - ConcurrentModificationException In a Java BO -



exception - ConcurrentModificationException In a Java BO -

i getting java.util.concurrentmodificationexception in code , can't seem understand why, or prepare it.

in bo have (privileges arraylist within bo)

public void setprivilegename(string privilegename) { this.privileges.add(privilegename); } list<privilegeobjectbo> arraylist = new arraylist<privilegeobjectbo>();if (rs != null) { while (rs.next()) { (bo bo : arraylist) { if (bo.getrolepkey()==rs.getint("role_pkey")) { bo.setprivilegename(rs.getstring("sp.name")); }else{ bo newobj = new bo(); newobj.setrolepriviledgepkey(rs.getint("privilege_pkey")); newobj.setproticolpkey(protocol); newobj.setprivilegename(rs.getstring("sp.name")); newobj.setrolepkey(rs.getint("srp.role_pkey")); arraylist.add(newobj); } } } }

in java, concurrentmodificationexception when modify collection while iterating on it.

possible solution: utilize temporary collection added or deleted items, , add together or delete items after iteration done.

java exception

No comments:

Post a Comment