I am looking for a way to either
a) clone an OntModel in a performant way
b) make OntModel instance in OntDocumentManager read-only
The use case goes like this: JAX-RS retrieves an OntModel instance
from OntModel manager per each request, adds to it or changes it, and
discards it after the request.
We cannot directly change the OntModel instance in OntDocumentManager,
because that would pollute it with changes from each request and the
size would grow very quickly.
So I went for the easy way out and cloned the OntModel on each
request, like this:
OntModel ontModel =
// lock and clone the model to avoid ConcurrentModificationExceptions
Model baseModel =
OntModel clonedModel =
if (log.isDebugEnabled()) log.debug("Sitemap model size:
That works, but the problem is that cloning using add() performs very
poorly. According to my profiling, this code takes almost a second to
execute with under 6000 statements, spent mostly in hasNext() of
Not sure if it's relevant, but the OntModelSpec uses GenericRuleReasoner.
Is there a faster way or can you maybe suggest a different approach altogether?