I am using an RDF file to store links (URLs) of online resources that are added by different users about various topics.
I am using Jena API to read and write the RDF file, on Apache server.
My concern is that multiple users would allowed at the same time to login to the system and may interact with the file at the same time.
I am wondering if this would cause any problem in updating the file, for example, will it corrupt the file in some way. Can I go ahead with this for live application or will it crash my application as a result of RDF file being accessed by multiple users for read and write at the same time.
I would really appreciate the help.
Thanks
Syed
//updated code to understand answer.
// Example of Locks for reading
File f = new File(fileName);
InputStream in = new FileInputStream(f);
Model model = ModelFactory.createDefaultModel();
model.read(in,null);
String queryString = "...";
model.enterCriticalSection(Lock.READ); // use of lock
try {
qe = QueryExecutionFactory.create(qry, model);
rs = qe.execSelect();
for ( ; rs.hasNext() ; )
{
//read literals
//read literals
out.println(....);
}
qe.close();
} finally
{
model.leaveCriticalSection() ;
}
//******************************
// Example of Locks for WRITING
File fout = new File(fileName);
Model model = ModelFactory.createDefaultModel();
model.read(in,null);
OutputStream os = new FileOutputStream(fout);
// model updation
// new triplets. new data being added
model.enterCriticalSection(Lock.WRITE); // use of lock
try {
model.write(os);
} finally
{
model.leaveCriticalSection() ;
}
os.close();