Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala RDF4J应用程序赢得';不要终止_Scala_Sparql_Rdf4j - Fatal编程技术网

Scala RDF4J应用程序赢得';不要终止

Scala RDF4J应用程序赢得';不要终止,scala,sparql,rdf4j,Scala,Sparql,Rdf4j,在过去的几个月里,我一直在写大量的Scala+RDF4J。到目前为止还不错 我今天刚刚写了这篇文章,应用程序不会终止。它打印出请求的三个三元组和单词“done”,但不会返回到sbt命令提示符(或者,在Eclipse中,stop按钮保持红色,悬停在run按钮上会显示一条“已经运行的消息”) 我到底做错了什么?我在几个不同的端点上运行了它,包括RDF4J服务器、Virtuoso和Blazegraph 我的消息来源 import org.eclipse.rdf4j.query.QueryLanguag

在过去的几个月里,我一直在写大量的Scala+RDF4J。到目前为止还不错

我今天刚刚写了这篇文章,应用程序不会终止。它打印出请求的三个三元组和单词“done”,但不会返回到sbt命令提示符(或者,在Eclipse中,stop按钮保持红色,悬停在run按钮上会显示一条“已经运行的消息”)

我到底做错了什么?我在几个不同的端点上运行了它,包括RDF4J服务器、Virtuoso和Blazegraph

我的消息来源

import org.eclipse.rdf4j.query.QueryLanguage
import org.eclipse.rdf4j.repository.sparql.SPARQLRepository

object sharedMain {
  def main(args: Array[String]): Unit = {

    val sparqlEndpoint = "https://dbpedia.org/sparql"
    val SparqlRepo = new SPARQLRepository(sparqlEndpoint)
    SparqlRepo.initialize()

    var con = SparqlRepo.getConnection()

    var queryString = "SELECT ?x ?y WHERE { ?x ?p ?y } limit 3 "
    val tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString)
    var result = tupleQuery.evaluate()

    while (result.hasNext()) { // iterate over the result
      val bindingSet = result.next()
      val valueOfX = bindingSet.getValue("x")
      val valueOfY = bindingSet.getValue("y")
      val toPrint = valueOfX + " -> " + valueOfY
      println(toPrint)
    }

    result.close
    con.close

    println("done")
  }
}
我的身材.sbt

name := "tripleStoreTesting"
version := "0.1"
scalaVersion := "2.12.0"
resolvers += Classpaths.typesafeReleases
libraryDependencies ++= Seq(
    "ch.qos.logback" % "logback-classic" % "1.1.5" % "runtime",
    "org.scalactic" %% "scalactic" % "3.0.1",
    "org.scalatest" %% "scalatest" % "3.0.1" % "test",
    "org.eclipse.rdf4j" % "rdf4j-runtime" % "2.2.2",
    "commons-logging" % "commons-logging" % "1.2"
)
mainClass := Some("sharedMain")

正如AKSW所建议的,我没有关闭或关闭我打开、启动、初始化的所有内容

// Scala code snippet, 
// starting with my program's last interaction with the triplestore

while (result.hasNext) { // iterate over the result
  val bindingSet = result.next
  val valueOfX = bindingSet.getValue("x")
  val valueOfY = bindingSet.getValue("y")
  val toPrint = valueOfX + " -> " + valueOfY
  println(toPrint)
}

result.close
con.close

// ADD THIS for proper application termination
SparqlRepo.shutDown
除此之外,编程教程还很好地强调了许多需要正确关闭的内容

  • 联系
  • 结果迭代器
  • 语句迭代器
  • 输入流
  • 当然,文件

它只是没有特别提到关闭
SPARQLRepository
实例。

也许在末尾添加
sparqlRepo.shutDown()
会有帮助吗?Scaladoc:是的,在
con.close
之后添加
sparqrepo.shutDown()。谢谢。@MarkMiller将你的评论作为一个答案-我相信其他人将来会在这个问题上绊倒:)