We are trying to find the best solution to write concurrently to the same semantic model. We have at times more than 20+ threads requesting to update triples in the semantic model. We are currently creating a synchronized block around the operation that all of the threads use to only allow one of the threads access to the editable model. When we did not use the syncronized block the INS and DEL triggers on the Application Table creating deadlocks.
Is there a best practice for writing to the same model at the same time? Any guidence would be helpful.
The scenario that causes the deadlock is exactly the same as what occurs during concurrent DML into a relational table with a unique constraint.
Underneath, the semantic store too has a uniqueness constraint defined to prevent duplicate RDF triples in the same RDF model. So, suppose one transaction T1 inserts triple (a,b,c), a second trans T2 inserts triple (d,e,f). Then the first transaction T1 tries to insert the triples (d,e,f), but it blocks because this triple has already been inserted by the yet-to-be-committed transaction T2. Now, when the second transaction T2 tries to insert triple (a,b,c), it blocks as well because this triple has already been inserted by the yet-to-be-uncommitted transaction T1. So, this circularity brings us to a deadlock and Oracle would raise ORA-00060: deadlock detected while waiting for resource.
Since this is exactly how deadlock may occur in any relational table with unique constraints defined on it, the best practice for avoiding deadlock would be the same for concurrent inserts into the same RDF model.