我正在使用RDFConnectionFactory连接到使用Spring Boot的Web应用程序中的远程fuseki服务器,但是当我尝试连接5次时连接被阻止(每次重启总是成功5次然后被阻止)。我的代码有问题吗?
public RDFResult query(String queryString) {
RDFConnection connection = RDFConnectionFactory.connect(host);
System.out.println("CONNECTED");
RDFResult result;
try {
connection.begin(ReadWrite.READ);
System.out.println("TRANSACTION BEGIN");
System.out.println(connection.isInTransaction());
ResultSet rs = connection.query(queryString).execSelect();
result = new RDFResult();
result.setVarNames(rs.getResultVars());
while (rs.hasNext()) {
QuerySolution qs = rs.next();
List<String> row = result.getVarNames().stream().map(e -> qs.get(e).toString()).collect(Collectors.toList());
result.getResultSet().add(row);
}
connection.end();
} catch (Exception e) {
throw new RuntimeException();
} finally {
connection.abort();
connection.close();
System.out.println("asdfasdf");
}
return result;
}
答案 0 :(得分:2)
我解决了这个问题! execSelect需要明确关闭......