Search code examples
jenaconcurrentmodification

Jena java.util.ConcurrentModificationException with execConstruct


executing the following code:

     Query query = QueryFactory.create(queryString);      
     QueryExecution qexec = QueryExecutionFactory.create(query, model);          
     Model m = qexec.execConstruct(model);     
     System.out.println(m.toString());
     model.close();

sometimes arises the java.util.ConcurrentModificationException exeception, depending on the type of query I'm executing. There is a way to build an always-safe snippet of code? Thank you.


Solution

  • Use Model m = qexec.execConstruct() (no model argument) then call model.add(m).

    If you query and insert statements on the same model, via execConstruct(model)) there is a risk of CCME. Using a different model for the results avoids that.