在 hasNext() 调用时冻结 while 循环
Freezing while loop on hasNext() invocation
我在调用基本 hasNext()
方法时遇到了一些问题。
我不明白为什么会这样。在执行过程中有一段时间程序将经历 3 次迭代
StmtIterator statementIt = m.listStatements(null, p, obj);
Statement stamt = null;
List<Resource> lres = new ArrayList<Resource>();
while (statementIt.hasNext())
{
stamt = (Statement)statementIt.next();
System.out.println("Debugging: " + stamt.getSubject().toString());
if(!stamt.getSubject().isURIResource())
{
break;
}
if(!lres.contains((Resource)stamt.getSubject()))
lres.add((Resource)stamt.getSubject());
System.out.println("debugging: there will be another iteration: " + statementIt.hasNext());
}
它确实经历了 3 次,但随后在尝试执行 hasNext()
操作时挂起。我试图通过调试视图查看程序的配置文件(我使用 Eclipse 进行开发 Java),虽然我不是这个调试工具的主人,但我没有找到任何相关的信息来查明异常。
这里一头雾水,求助D:
感谢@user205512 和@JoshuaTaylor 我能够找到问题。
我正在使用一个推理器,它会挂起程序寻找更多的节点,但从未真正在它上面工作(默认的 Jena 包为推理器实现了一个接口,但没有工作的推理器)。
解决方案:要么放弃使用推理机(在使用本体时不是很重要),要么得到一个合适的推理机并让它工作(我目前正在尝试驯服 Pellet 推理机 :P )
我在调用基本 hasNext()
方法时遇到了一些问题。
我不明白为什么会这样。在执行过程中有一段时间程序将经历 3 次迭代
StmtIterator statementIt = m.listStatements(null, p, obj);
Statement stamt = null;
List<Resource> lres = new ArrayList<Resource>();
while (statementIt.hasNext())
{
stamt = (Statement)statementIt.next();
System.out.println("Debugging: " + stamt.getSubject().toString());
if(!stamt.getSubject().isURIResource())
{
break;
}
if(!lres.contains((Resource)stamt.getSubject()))
lres.add((Resource)stamt.getSubject());
System.out.println("debugging: there will be another iteration: " + statementIt.hasNext());
}
它确实经历了 3 次,但随后在尝试执行 hasNext()
操作时挂起。我试图通过调试视图查看程序的配置文件(我使用 Eclipse 进行开发 Java),虽然我不是这个调试工具的主人,但我没有找到任何相关的信息来查明异常。
这里一头雾水,求助D:
感谢@user205512 和@JoshuaTaylor 我能够找到问题。
我正在使用一个推理器,它会挂起程序寻找更多的节点,但从未真正在它上面工作(默认的 Jena 包为推理器实现了一个接口,但没有工作的推理器)。
解决方案:要么放弃使用推理机(在使用本体时不是很重要),要么得到一个合适的推理机并让它工作(我目前正在尝试驯服 Pellet 推理机 :P )