public class ThreadedSPARQL extends SPARQL
SPARQL.sparql(String) will block, if server doesn't respond. Here, you can set a maximum time limit.
This is achieved by wrapping underlying SPARQL in a Thread, which then has a maximum execution time.
| Modifier and Type | Field and Description |
|---|---|
private ExecutorService |
executor |
private org.slf4j.Logger |
log |
private int |
timeoutInSeconds |
| Constructor and Description |
|---|
ThreadedSPARQL()
#ENDPOINT_DBPEDIA_ORG as endpoint used. |
ThreadedSPARQL(int timeoutInSeconds,
String endpoint) |
ThreadedSPARQL(String endpoint)
Default timeout : 10 seconds
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Call this to close the underlying thread pool.
|
int |
getTimeoutInSeconds() |
void |
setTimeoutInSeconds(int timeoutInSeconds) |
Set<org.apache.jena.rdf.model.RDFNode> |
sparql(String query)
Fire a sparql query against endpoint defined in constructor.
|
executeAsk, executeSelect, extractAnswerStrings, getCacheTimeToLive, isEndpointAlive, isValidSparqlQuery, setCacheTimeToLiveprivate int timeoutInSeconds
private final org.slf4j.Logger log
private ExecutorService executor
public ThreadedSPARQL()
#ENDPOINT_DBPEDIA_ORG as endpoint used.
Default timeout : 10 seconds
public ThreadedSPARQL(String endpoint)
public ThreadedSPARQL(int timeoutInSeconds,
String endpoint)
timeoutInSeconds - - set a maximum time limit for the execution of one query. Only set if >0 otherwise ignored (default=10s)endpoint - - A sparql endpoint, e.g. SPARQLEndpoints.DBPEDIA_ORGpublic Set<org.apache.jena.rdf.model.RDFNode> sparql(String query)
This will break operation after timeoutInSeconds has been reached. in this case, null is returned.
For string representation of answers, see SPARQL.extractAnswerStrings(Set)
public int getTimeoutInSeconds()
public void setTimeoutInSeconds(int timeoutInSeconds)
timeoutInSeconds - - the time after a query times out.public void destroy()
Copyright © 2016–2020. All rights reserved.