zfm
zfm

Reputation: 2006

adding timeout to jena (for sparql) using dbpedia as end point?

I would like to know whether there is a way to use Jena to do a sparql query through dbpedia and using the timeout setting given in http://dbpedia.org/sparql (if you see this page, you could see that there is a way to set the timeout there), this is needed since I would like to make a big query and I have tried several times (via the page) that without setting the timeout, I cannot get the result (it is always a transaction timeout exception)

edited: I use java.

Upvotes: 4

Views: 1841

Answers (2)

I would do it like this:

String service = "http://dbpedia.org/sparql";
QueryExecution qexec = QueryExecutionFactory.create(query, service) ;
qexec.setTimeout(10, TimeUnit.MINUTES);

ResultSet results = qexec.execSelect() ;
String result = ResultSetFormatter.asText(results);

If if the timeout limit it reached then a org.apache.jena.query.QueryCancelledException is thrown.

Upvotes: 0

Manuel Salvadores
Manuel Salvadores

Reputation: 16525

To execute your query, I guess you're using :

QueryExecutionFactory.sparqlService(String service, Query query) 

One thing you could try is:

QueryEngineHTTP objectToExec=QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql",YOUR_QUERY);
objectToExec.addParam("timeout","5000"); //5 sec
resultset=objectToExec.execSelect();

It seems that QueryEngineHTTP implements QueryExecution which has an addParam method. There's no description of that method but I'd assume that adds a parameter to the HTTP request.

Let me know if it works !!

Edited to fix error actually it was the other way around ... QueryEngineHTTP implements QueryExecution

Upvotes: 3

Related Questions