Frequently Asked Questions

Is the RDF API thread-safe?

All MGraphs returned by TcManager are LockableMgraphs, this graphs are thread-safe independently on whether the underlying provider is thread-safe or not. Note however that like the synchronized collections returned by java.util.Collections a ConcurrentModificationException may occur when the TripleCollection is modified while iterating over it. To be sure that no other thread may do any modification while iterating over it, the iterating thread may acquire a ReadLock using the following construct:
Lock l = mGraph.getLock().readLock(); l.lock(); try { Iterator<Triple> iter = mGraph.filter(...); //iterate over triples } finally { l.unlock(); }
Note that single method invocations always lock the TripleCollection, but if you need a lock to span multiple method invocation you need to acquire a (read or write) lock as described above.