简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM