You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hadoop.apache.org by 罗 辉 <lu...@zetyun.com> on 2017/12/06 08:42:30 UTC

Do I need to reconnect hdfs in a long running app?

Hi there:
I have a small app like below:
import org.apache.hadoop.fs._
import org.apache.hadoop.fs.FileSystem._
import org.apache.hadoop.conf._

object App {
  def main(args: Array[String]) {
    val path = "/user/root"
    val hdfspath = new Path(path)
    val recursive = true
    val uri = new java.net.URI("hdfs://dserver1:8020")
    val conf = new Configuration
    val fs = FileSystem.get(uri, conf)
    while (true) {
      val files = fs.listFiles(hdfspath, recursive)
      while (files.hasNext()) {
        println(files.next().getPath)
      }
      Thread.sleep(5000)
    }
  }
}

And my question is : I’ve got a concern about while looping long enough, will my app lose the connection to hdfs?  If yes, how to reconnect to HDFS in a try catch code block?
Thank you guys
San.Luo