Hey,

in our webapp, all objects are created per-request, except ontologies
stored in a shared OntDocumentManager, that are accessed like this:

  OntDocumentManager.getInstance().getOntology(ontologyURI, ontModelSpec);

This has caused some ConcurrentModificationExceptions. I have read the
https://jena.apache.org/documentation/notes/concurrency-howto.html
document, and wanted to check if I get this right.

Basically, every operation and iterator on a shared OntModel has to be
in a critical section? Even if it's indirect and called on an OntClass
from the OntModel:

  OntModel ontModel =
OntDocumentManager.getInstance().getOntology(ontologyURI,
ontModelSpec);
  ontModel.enterCriticalSection(Lock.READ);
  try
  {
    OntClass ontClass = ontModel.getOntClass("http://some/class";);
    NodeIterator it = ontClass.listPropertyValues(GC.supportedMode);
    try
    {
      while (it.next)
        ...
    }
    finally
    {
      it.close();
    }
  }
  finally
  {
    model.leaveCriticalSection() ;
  }

Is that correct?

Martynas

Reply via email to