I have a suite of webservices which use OWL ontologies stored as named graphs
in an SDB database. I also have a set of Java objects that provide a POJO
façade over ontology class instances. These instances import many or even all
of the OWL ontologies, so I have an OntDocumentManager which points to cached
versions of the ontologies.
When an ontology changes, I need to update it in the database, then re-cache it
in the OntDocumentManager. During those operations (update ontology graph in
database, update cached version in OntDocumentManager) I am within a
try/finally block that (respectively) is a write lock or a read lock.
So a sketch (not the full implementation) of the code for writing and reading
would be:
void update(String name, Model newModel) {
Model model = SDBFactory.connectNamedModel(store, name);
try {
model.enterCriticalSection(false); // write
model.removeAll();
model.add(newModel);
}
finally {
model.leaveCriticalSection();
}
}
void cache(OntDocumentManager mgr, String name) {
Model model = SDBFactory.connectNamedModel(store, name);
Model cachedModel = createModel(); // this method creates an
OWL_MEM model with the doc mgr as its document manager, etc.
try {
model.enterCriticalSection(true); // read
cachedModel.add(model);
}
finally {
model.leaveCriticalSection();
}
mgr.addModel(name, cachedModel, true);
}
What appears to happen is that these critical sections don't appear to inhibit
other users (in my tests I have five) of the SDB database from modifying the
stored graph. Readers of the graphs sometimes end up with empty graphs. I will
sometimes end up with stored graphs that are empty, or inconsistent in some way
that eventually corrupts the underlying tables in the database, requiring a
complete reinitialization. I also get IllegalThreadState exceptions. Many
different exceptions are thrown, with little obvious consistency.
Is critical section only good within a JVM? Do I need to use some sort of
transaction instead?
Does anyone have any advice or ideas?
Dave
David Lebling
Principal Software Engineer
BAE Systems, ACDS Group