【发布时间】:2015-09-29 13:37:04
【问题描述】:
我在使用 SPARQL 查询芝麻三联商店时遇到了问题。在我成功运行多个查询后,与三重存储的连接会阻塞。我已经能够在AbstractConnPool.getPoolEntryBlocking 第 306 行查明问题:apache-httpcomponents 库的success = future.await(deadline);。如果我理解正确,则此方法会在超出最大连接数时阻塞。最大为 5 个连接,实际上此时池中打开的连接数为 5。
我不明白为什么此时有 5 个打开的连接。
当我在TupleQuery 上调用evaluate 方法时,就会出现问题。每次我打开一个新的连接时
connection = repository.getConnection();
我也关闭它:
} finally {
if(connection!=null){
try {
connection.close();
nclosedconnections++;
System.out.println("Connections: "+nconnections+" closed: "+nclosedconnections);
} catch (RepositoryException e) {
throw new SearchException("Could not close the triple store as a search engine.",this,null,e);
}
}
}
我检查了RepositoryConnection 的开放频率和关闭频率。当方法阻塞时,RepositoryConnection 已打开 6 次并已关闭 5 次,正如预期的那样。
每个连接也只使用一次(即用于一个 SPARQL 查询)。我也尝试过重用连接,但我仍然得到相同的块。
你有什么想法,为什么会出错,我该如何解决这个问题?
注意。 Sesame 存储库在 tomcat 上运行,并通过 HTTP 建立连接,即存储库是 HTTPRepository,由以下人员创建:
repository = new HTTPRepository(repositoryURL);
repository.initialize();
我也查看了服务器上的芝麻日志,但是芝麻服务器没有收到请求。问题似乎出在没有发送请求的客户端。
NB2。下面是更完整的代码-sn-p:
RepositoryConnection connection = null;
String sparql = "" +
"SELECT * WHERE {\n" +
" OPTIONAL{ <"+result.getURI()+"> <" + DC.TITLE+ "> ?title. }"+
" OPTIONAL{ <"+result.getURI()+"> <" + RDFS.LABEL+ "> ?label. }"+
" OPTIONAL{ <"+result.getURI()+"> <" + SKOS.PREF_LABEL+ "> ?prefLabel. }"+
" OPTIONAL{ <"+result.getURI()+"> <" + SKOS.ALT_LABEL+ "> ?altLabel. }"+
" OPTIONAL{ <"+result.getURI()+"> <" + DC.DESCRIPTION+ "> ?description. }"+
" OPTIONAL{ <"+result.getURI()+"> <" + RDFS.COMMENT+ "> ?comment. }"+
"}\n";
try{
connection = repository.getConnection();
nconnections++;
System.out.println("Connections: "+nconnections+" closed: "+nclosedconnections);
TupleQuery query = connection.prepareTupleQuery(QueryLanguage.SPARQL,sparql);
query.setMaxExecutionTime(2);
TupleQueryResult results = query.evaluate();
while (results.hasNext()){
...
}
} catch (RepositoryException e) {
throw new SearchException("Could not access the triple store as a search engine.",this,null,e);
} catch (QueryEvaluationException e) {
throw new SearchException("Could retrieve data from the triple store as the SPARQL query could not be evaluated. SPARQL:\n"+sparql,this,null,e);
} catch (MalformedQueryException e) {
throw new SearchException("Could retrieve data from the triple store as the SPARQL query was malformed. SPARQL:\n"+sparql,this,null,e);
} finally {
if(connection!=null){
try {
connection.close();
nclosedconnections++;
System.out.println("Connections: "+nconnections+" closed: "+nclosedconnections);
} catch (RepositoryException e) {
throw new SearchException("Could not close the triple store as a search engine.",this,null,e);
}
}
}
【问题讨论】:
标签: apache-httpcomponents sesame