简体   繁体   中英

RDF4J only scheduling 5 Queries against a Triple Store

I have some more Issues with handling semantic data technologies: I have a GraphDB Triplestor running locally on my machine an try to schedule some SPARQL queries against it using RDF4J and Java. As you can see from the code below 10 Queries shall be launched in a row. However only 5 get launched (I see number 0 - 4 in console). The problem seems to be that I am limited to 5 open HTTP connections for some reason. Any call of repConn.close() does not seem to change anything. Any Ideas anyone?

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);

    }
}

}

you also need to close the query result otherwise the repCon.close does not do anything.

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

    }

Or even better use the new rdf4j streams API(QueryResults.stream(gqr)). That closes everything for you. http://docs.rdf4j.org/migration/ (Point 2.6.5)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM