marandus
marandus

Reputation: 1258

Jena TDB hangs/freezes on named model access

I have a problem with Apache Jena TDB. Basically I create a new Dataset, load data from an RDF/XML file into a named model with the name "http://example.com/model/filename" where filename is the name of the XML/RDF file. After loading the data, all statements from the named model are inserted into the default model. The named model is kept in the dataset for backup reasons.

When I now try to query the named models in the Dataset, TDB freezes and the application seems to run in an infinite loop, so it is not terminated nor does it throw an exception.

What is causing that freeze and how can I prevent it?

Example code:

Dataset ds = TDBFactory.createDataset("tdb");
Model mod = ds.getDefaultModel();

File f = new File("example.rdf");
FileInputStream fis = new FileInputStream(f);

ds.begin(ReadWrite.WRITE);

// Get a new named model to load the data into
Model nm = ds.getNamedModel("http://example.com/model/example.rdf");
nm.read(fis, null);

// Do some queries on the Model using the utility methods of Model, no SPARQL used

// Add all statements from the named model to the default model
mod.add(nm);

ds.commit();
ds.end();

// So far everything works as expected, but the following line causes the freeze
Iterator<String> it = ds.listNames();

Any method call that accesses the existing named models causes the same freeze reaction, so this is the same for getNamedModel("http://example.com/model/example.rdf"); for example. Adding new named models by calling getNamedModel("http://example.com/model/example123.rdf"); works fine, so only access to existing models is broken.

Used environment: Linux 64bit, Oracle Java 1.7.0_09, Jena 2.7.4 (incl. TDB 0.9.4)

Thanks in advance for any help!

Edit: Fixed mistake in code fragment

Edit2: Solution (my last comment to AndyS answer)

Ok, I went through the whole program and added all missing transactions. Not it is working as expected. I suspect Jena throwing an Exception during the shutdown sequence of my program but that Exception was not reported properly and the "freeze" was caused by other threads not terminating correctly. Thanks for pointing the faulty transaction usage out.

Upvotes: 2

Views: 514

Answers (1)

AndyS
AndyS

Reputation: 16630

Could you turn this into a test case and send it to the jena users mailing list please?

You should get the default model inside the transaction - you got it outside.

Also, if you have used a dataset transactionally, you can't use it untransactionally as you do at ds.listNames. It shouldn't freeze - you should get some kind of warning.

Upvotes: 1

Related Questions