Re: Concurrent access to a shared (Ont)Model

2016-08-26 Thread Martynas Jusevičius
Sorry, false alarm: this turned out to be a simpler case of Model modification during iteration, obscured by a recursive call. On Fri, Aug 26, 2016 at 8:04 PM, Martynas Jusevičius wrote: > Hey Dave, > > another case of this came up. When calling imports.hasNext() on > >

Re: Concurrent access to a shared (Ont)Model

2016-08-26 Thread Martynas Jusevičius
Hey Dave, another case of this came up. When calling imports.hasNext() on ExtendedIterator imports = ontology.listImports(); I consistently get ConcurrentModificationException: at org.apache.jena.reasoner.rulesys.impl.LPTopGoalIterator.checkCME(LPTopGoalIterator.java:248) at

Re: Concurrent access to a shared (Ont)Model

2016-07-25 Thread Martynas Jusevičius
Dave, I was doing OntModel ontModel = OntDocumentManager.getInstance().getOntology(ontologyURI, ontModelSpec); ... OntModel clonedModel = ModelFactory.createOntologyModel(ontModelSpec); where ontModelSpec was new OntModelSpec(OntModelSpec.OWL_MEM) with GenericRuleReasoner set. I guess I

Re: Concurrent access to a shared (Ont)Model

2016-07-23 Thread Dave Reynolds
On 22/07/16 21:42, Martynas Jusevičius wrote: Is clonedModel.add(ontModel) the best way to clone a model though? Because after that ontModel.size() and clonedModel.size() seem to differ sometimes, e.g. 4723 vs 4729. I expect you've got inference enabled on both ontModel and clonedModel. In

Re: Concurrent access to a shared (Ont)Model

2016-07-22 Thread Martynas Jusevičius
Is clonedModel.add(ontModel) the best way to clone a model though? Because after that ontModel.size() and clonedModel.size() seem to differ sometimes, e.g. 4723 vs 4729. On Fri, Jul 22, 2016 at 9:24 AM, Dave Reynolds wrote: > On 21/07/16 22:26, Martynas Jusevičius

Re: Concurrent access to a shared (Ont)Model

2016-07-22 Thread Dave Reynolds
On 21/07/16 22:26, Martynas Jusevičius wrote: Thanks Dave. Does the following code look reasonable? OntModel ontModel = OntDocumentManager.getInstance().getOntology(ontologyURI, ontModelSpec); ontModel.enterCriticalSection(Lock.READ); try {

Re: Concurrent access to a shared (Ont)Model

2016-07-21 Thread Martynas Jusevičius
Thanks Dave. Does the following code look reasonable? OntModel ontModel = OntDocumentManager.getInstance().getOntology(ontologyURI, ontModelSpec); ontModel.enterCriticalSection(Lock.READ); try { OntModel clonedModel =

Re: Concurrent access to a shared (Ont)Model

2016-07-20 Thread Dave Reynolds
So that's the reasoner in which case you need to lock the OntModel. Dave On 19/07/16 17:04, Martynas Jusevičius wrote: Hey Andy, I am not sure yet what is it that I need to lock - is it the OntModel, or the OntDocumentManager instance, or maybe both. But here are 2 actual exceptions:

Re: Concurrent access to a shared (Ont)Model

2016-07-19 Thread Martynas Jusevičius
Hey Andy, I am not sure yet what is it that I need to lock - is it the OntModel, or the OntDocumentManager instance, or maybe both. But here are 2 actual exceptions: java.util.ConcurrentModificationException at

Re: Concurrent access to a shared (Ont)Model

2016-07-19 Thread Andy Seaborne
On 17/07/16 13:54, Martynas Jusevičius wrote: But then again, I cannot lock what I don't have: locks work on models, and I only get OntModel instance when getOntology() is called. Maybe synchronized is the solution here? You can lock how you like - the Jena lock code is helper code, to

Re: Concurrent access to a shared (Ont)Model

2016-07-17 Thread Martynas Jusevičius
But then again, I cannot lock what I don't have: locks work on models, and I only get OntModel instance when getOntology() is called. Maybe synchronized is the solution here? On Sun, 17 Jul 2016 at 15:32, Martynas Jusevičius wrote: > Thanks Andy. > > All of our code

Re: Concurrent access to a shared (Ont)Model

2016-07-17 Thread A. Soroka
As I read the code, getOntology is a write operation just when it doesn't retrieve a pre-existing (cached) OntModel and must build a new one. If you can be sure that you have always beforehand written the OntModel you are retrieving into the OntDocumentManager using addModel, then I don't think

Re: Concurrent access to a shared (Ont)Model

2016-07-17 Thread Martynas Jusevičius
Thanks Andy. All of our code except OntDocumentManager access uses imutable objects, so I hope to keep lock usage to an absolute minimum. Transactions look like an overkill at this point. So if getOntology() is a write operation, if I wrap only this piece of code where it is called into a WRITE

Re: Concurrent access to a shared (Ont)Model

2016-07-17 Thread A. Soroka
From my reading of the code, you will want explicitly add Models from a TIM dataset to the OntDocumentManager instance. In other words, don't use getOntology with having added the Model yourself, or the OntDocumentManager instance will create a Model outside the TIM dataset to give you. But I

Re: Concurrent access to a shared (Ont)Model

2016-07-16 Thread Martynas Jusevičius
On a second thought, since our code is only reading from the models, it is probably easier and safer just to clone the shared model into a per-request copy, and keep the code as it is. Is the following code the fastest way to do it? Is add() expensive? OntModel ontModel =