1 Replies - 305 Views - Last Post: 06 November 2017 - 10:48 AM Rate Topic: -----

#1 Criel   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 146
  • Joined: 11-March 11

ConcurrentModificationException occuring very sporadically

Posted 06 November 2017 - 09:17 AM

We recently moved to CompletableFuture to save us on some latency we were seeing with our subsequent dependencies with our microservice, switching to CompletableFuture saved a ton of overall processing time but we are seeing < 1% failure for no particular reason.

We are seeing :

OUT Caused by: java.util.ConcurrentModificationException: null

in one of the dependency calls when the call is actually returning back a 200, so assuming there's an issue with the code after the call. We are simply looping through and calling that dependency for the number of users in the account and adding the response to that into one 'master' object which will be used later in the application.

Main class :

  dependencyResponse1 = async.GetDependency1Response(account);                
            dependencyResponse2 = async.GetDependency2Response(account);
            dependencyResponse3 = async.GetDependency3Response(account);
            CompletableFuture.allOf(dependencyResponse1, dependencyResponse2, dependencyResponse3).join();

            //continue with main thread code

private ConcurrentHashMap<String, DependencyPojo1> dependency1Map = new ConccurentHashMap<>();

    public CompletableFuture<Map<String, DependencyPojo1>> GetDependencyResponse1(ArrayList<String> accounts) throws Throwable
DependencyPojo1 dependencyResponse = null;

            Iterator<String> it = accounts.iterator();
                String value = it.next();
                dependencyResponse =  service.invokeDependency(value);
                dependencyMap.put(value, dependencyResponse);
        catch(CompletionException ex)
            try {
                throw ex.getCause();
            catch(Error|RuntimeException|ServerException|RequestProcessingException possible) {
                throw possible;
            catch(Throwable impossible) {
                throw new Assertionerror(impossible);
        return CompletableFuture.completedFuture(dependencyMap);        

Is this extremely sporadic error coming from when we add the response to the map object? I've read and this normally occurs when you are modifying an active list such as deleting objects from a list in use, but does this also bear true for when simply adding info to a conccurentHashMap?

Is This A Good Question/Topic? 0
  • +

Replies To: ConcurrentModificationException occuring very sporadically

#2 CasiOo   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1577
  • View blog
  • Posts: 3,551
  • Joined: 05-April 11

Re: ConcurrentModificationException occuring very sporadically

Posted 06 November 2017 - 10:48 AM

My guess is that your accounts list is being modified while it is being iterated. Your iterator will then throw ConcurrentModificationException
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1