我的Java应用程序遇到问题。
我正在尝试在Fuseki服务器上进行请求,以从加载在其上的本体中获取响应。
在我的第五个请求上,服务器阻塞并且不返回任何响应,有时我收到此错误
验证:Web应用程序[MiCorr-WebServices]仍在处理尚未完成的请求。这很可能造成内存泄漏。您可以使用标准Context实现的unloadDelay属性来控制请求完成所允许的时间。请求处理线程的堆栈跟踪:[
sun.misc.Unsafe.park(Native Method) java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
我尝试对查询求逆,以查看问题是否出自查询,但结果相同。
有人可以帮助我找到解决此问题的方法吗?您可以看到我用来查询目录服务器的Java类。我不太确定,但是在前四个查询中都得到了不错的结果。
public class OntologyService {
private Artefacts artefacts;
private List<QuerySolution> querySolutionList;
private RDFConnectionRemoteBuilder builder;
private OntologyQuery query;
public OntologyService() {
// - Création de la connexion sur le serveur Fuseki
builder = RDFConnectionFuseki.create().destination("http://localhost:8080/MiCorrDS/")
.gspEndpoint("MiCorrGraph");
RDFConnectionFuseki conn = (RDFConnectionFuseki) builder.build();
query = new OntologyQuery(conn);
artefacts = new Artefacts();
}
public Artefacts getResearchProperties(String text, String country, String metalFamily, String corrosionForms,
String environments) {
querySolutionList = new ArrayList<>();
// - Recherche si le texte saisi existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(text);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setText(artefact.getLiteral("?artefactName").getString());
artefacts.setTextId(artefact.getLiteral("?artefactId").getInt());
artefacts.setTextType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setText("");
artefacts.setTextId(0);
artefacts.setTextType("");
}
// - Recherche si le pays saisi existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(country);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setCountry(artefact.getLiteral("?artefactName").getString());
artefacts.setCountryId(artefact.getLiteral("?artefactId").getInt());
artefacts.setCountryType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setCountry("");
artefacts.setCountryId(0);
artefacts.setCountryType("");
}
// - Recherche si le famille du métal saisie existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(metalFamily);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setMetalFamily(artefact.getLiteral("?artefactName").getString());
artefacts.setMetalFamilyId(artefact.getLiteral("?artefactId").getInt());
artefacts.setMetalFamilyType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setMetalFamily("");
artefacts.setMetalFamilyId(0);
artefacts.setMetalFamilyType("");
}
// - Recherche si la forme de corrosion saisie existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(corrosionForms);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setCorrosionForms(artefact.getLiteral("?artefactName").getString());
artefacts.setCorrosionFormsId(artefact.getLiteral("?artefactId").getInt());
artefacts.setCorrosionFormsType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setCorrosionForms("");
artefacts.setCorrosionFormsId(0);
artefacts.setCorrosionFormsType("");
}
// - Recherche si l'environnement saisi existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(environments);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setEnvironments(artefact.getLiteral("?artefactName").getString());
artefacts.setEnvironmentsId(artefact.getLiteral("?artefactId").getInt());
artefacts.setEnvironmentsType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setEnvironments("");
artefacts.setEnvironmentsId(0);
artefacts.setEnvironmentsType("");
}
// - Recherche si le famille du métal saisie existe dans l'ontologie
querySolutionList = query.getPropertiesDataQuery(corrosionForms);
if (!querySolutionList.isEmpty()) {
QuerySolution artefact = (QuerySolution) querySolutionList.get(0);
artefacts.setCorrosionForms(artefact.getLiteral("?artefactName").getString());
artefacts.setCorrosionFormsId(artefact.getLiteral("?artefactId").getInt());
artefacts.setCorrosionFormsType(artefact.getResource("?artefactType").getLocalName());
} else {
artefacts.setCorrosionForms("");
artefacts.setCorrosionFormsId(0);
artefacts.setCorrosionFormsType("");
}
return artefacts;
}
}
和查询类
public class OntologyQuery {
private static final String FILENAME1 = "C:\\DEV\\SPARQL\\micorr_query1.txt";
private static final boolean CONSOLE_LOG = true;
private RDFConnectionFuseki conn;
public OntologyQuery(RDFConnectionFuseki remoteConn) {
conn = remoteConn;
}
public List<QuerySolution> getPropertiesDataQuery(String text) {
String sparqlRequest = readFileToString(FILENAME1);
sparqlRequest = sparqlRequest.replaceAll("%text%", text);
System.out.println(sparqlRequest);
Query query = QueryFactory.create(sparqlRequest);
List<QuerySolution> list = null;
// In this variation, a connection is built each time.
if(CONSOLE_LOG) {
conn.queryResultSet(query, ResultSetFormatter::out);
}
list = ResultSetFormatter.toList(conn.query(query).execSelect());
return list;
}
private static String readFileToString(String filename) {
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
sb.append(sCurrentLine);
sb.append(" ");
}
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
}
这是SPARQL查询
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl:<http://www.w3.org/2002/07/owl#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX vocab:<http://micorr.ig.he-arc.ch/vocab#>
PREFIX ont: <http://www.co-ode.org/ontologies/ont.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?artefact ?artefactId ?artefactType ?artefactName
FROM <http://localhost:8080/MiCorrDS/data/MiCorrGraph>
WHERE {
?artefact a ?artefactType .
?artefact rdfs:label "%text%" .
BIND(IRI(CONCAT(STR(?artefactType), "_id")) AS ?iriConcat)
BIND("%text%" AS ?artefactName)
?artefact ?iriConcat ?artefactId .
FILTER( STRSTARTS(str(?artefactType), "http://micorr.ig.he-arc.ch/vocab") )
}
感谢您的帮助。