RDF4J仅针对三重存储调度5个查询

时间:2017-05-01 19:51:15

标签: java rdf semantic-web graphdb rdf4j

我在处理语义数据技术方面还有一些问题: 我有一台在我的机器上本地运行的GraphDB Triplestor尝试使用RDF4J和Java安排一些针对它的SPARQL查询。从下面的代码中可以看出,10个查询应该连续启动。但是只有5个启动(我在控制台中看到数字0 - 4)。问题似乎是我出于某种原因限于5个开放的HTTP连接。对repConn.close()的任何调用似乎都没有改变任何东西。任何人的想法?

import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.http.HTTPRepository;

public class testmain {

public HTTPRepository rep;
public RepositoryConnection repConn;

public static void main(String[] args) {

    testmain test = new testmain();

    test.rep = new HTTPRepository("http://localhost:7200/repositories/test01");

    //test.repConn = test.rep.getConnection();

    for (int i = 0; i < 10; i++) {

        test.repConn = test.rep.getConnection();
        String queryString = "select ?archiveID where { ?video <http://www.some.ns/ontology##hasArchiveID> ?archiveID .}";

        try {
            TupleQuery tupleQuery = test.repConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
            TupleQueryResult queryResult = tupleQuery.evaluate();
        } finally {
            test.repConn.close();
        }

        System.out.println(i);

    }
}

}

1 个答案:

答案 0 :(得分:1)

您还需要关闭查询结果,否则repCon.close不会执行任何操作。

try {
        TupleQuery tupleQuery = test.repConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
        TupleQueryResult queryResult = tupleQuery.evaluate();
        queryResult.close(); // this should solve your issue

    }

甚至更好地使用新的rdf4j流API(QueryResults.stream(gqr))。这会为你关闭一切。 http://docs.rdf4j.org/migration/(第2.6.5点)