我在研究项目中使用GraphDB Free 8.4.1,有时它无法响应请求。 GraphDB日志中没有错误,也没有异常,GraphDB以默认配置作为server + workbench运行。
但是,我在组件中有例外,那就是请求GraphDB服务器。
例外是:
org.eclipse.rdf4j.repository.RepositoryException: org.apache.http.NoHttpResponseException: The target server failed to respond
at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.exportStatements(HTTPRepositoryConnection.java:287)
at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.getStatements(HTTPRepositoryConnection.java:269)
at x.y.semantic.Repository.loadGraph(Repository.java:90)
发生异常的代码段:
ValueFactory factory = SimpleValueFactory.getInstance();
RepositoryConnection connection = repository.getConnection();
// exception happens in getStatements here:
RepositoryResult<Statement> result = connection.getStatements(null, null, null, true, factory.createIRI(contextURI));
能否请您帮助我确定问题出在哪里?
非常感谢您!
答案 0 :(得分:0)
GraphDB Free具有两个并发连接的限制。我怀疑问题是由GDB-1975“执行多个并发查询时冻结GraphDB Free”引起的。您可以使用以下方法轻松重现该问题:
for (int i = 0; i < 10; i++) {
RepositoryConnection repCon = repository.getConnection();
String queryString = "select * where {?s ?p ?o}";
try {
TupleQuery tupleQuery = repCon.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
//stops working after the 5th iteration
TupleQueryResult queryResult = tupleQuery.evaluate();
} finally {
//this does not close the connection because the queryResult was not closed
repCon.close();
}
System.out.println(i);
}
该代码不会关闭queryResult
迭代器,因此RDF4J使连接保持打开状态。我建议您使用可自动关闭的Java构造,并始终关闭所有迭代器,或升级到已修复该错误的8.6或更高版本。