collections - Concurrent Modification Exception in Java Set -


as part of program stuck concurrent modification exception. here mentioned part:

priorityqueue<customer> marginalgainheap = new priorityqueue<customer>(             1, new comparator<customer>() {                 public int compare(customer c1, customer c2) {                     return double.compare(c1.getmarginalgain(),                             c2.getmarginalgain());                 }             });      // set of remains available nodes     availablenodes.removeall(churnnet);     (customer avail : availablenodes) {         avail.setmarginalgain(0);         marginalgainheap.add(avail);     }     while (seedset.size() <= budget) {         **for (customer remainingnode : availablenodes) {**              remainingnode.setmarginalgain(calculatemarginalgain(                     remainingnode, seedset, network, availablenodes,                     churnnet));              marginalgainheap.remove(remainingnode);             marginalgainheap.add(remainingnode);         }         seedset.add(marginalgainheap.poll());     } 

here calculatemarginalgain method:

private int calculatemarginalgain(customer remainingnode,             hashset<customer> seedset,             directedsparsegraph<customer, transaction> net,             set<customer> availablenodes, hashset<customer> churnnetwork) {         // marginal gain short-term campaign         hashset<customer> tmp = new hashset<customer>(); // seedset u                                                             // {remainingnode}         tmp.add(remainingnode);         set<customer> tmpavailablenodes = availablenodes;         hashset<customer> neighborofchurn = getneighbors(churnnetwork, net);         // sigma function calculating expected number of influenced         // customers- seedsettmp=seedset u {u}         tmpavailablenodes.removeall(neighborofchurn);         set<customer> influencednet = getneighbors(tmp, net);         tmpavailablenodes.retainall(influencednet);         return tmpavailablenodes.size();     } 

i got exception on line of program specify **. find out error caused iterator. did not use one! please me find out caused exception , how can fix that?

regards.

converting set array may solve problem

example:

set<string> set = new set<string>(size); string[] array = set.toarray(new string[set.size()]); 

so in loop can that:

for(string foo : set.toarray(new string[notis.size()])) {     // loop stuff here } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -