Parallel file processing in Scala

后端 未结 6 692
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 03:17

Suppose I need to process files in a given folder in parallel. In Java I would create a FolderReader thread to read file names from the folder and a pool of

6条回答
  •  粉色の甜心
    2020-12-06 03:40

    Well, grab your files and stick them in a parallel structure

    scala> new java.io.File("/tmp").listFiles.par
    res0: scala.collection.parallel.mutable.ParArray[java.io.File] = ParArray( ... )
    

    Then...

    scala> res0 map (_.length)
    res1: scala.collection.parallel.mutable.ParArray[Long] = ParArray(4943, 1960, 4208, 103266, 363 ... )
    

提交回复
热议问题