-
-
Save Yuichiroh/6c1f0c9df80786ee13c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ParallelWritingWithApp extends App { | |
val seq = (0 until 100).map(_ * args(1).toInt) | |
for (w <- new PrintWriter(args(0))) | |
seq foreach w.println | |
implicit class Using[T <: AutoCloseable](resource: T) { | |
def foreach[R](op: T => R): R = { | |
try op(resource) | |
catch { case e: Exception => throw e } | |
finally resource.close() | |
} | |
} | |
} | |
object ParallelWritingTest extends App { | |
val maxes = (1 to 5).par.map { i => | |
(1 to 3).par.map { j => | |
val id = s"$i-$j.txt" | |
Console.err.println(s"write $id") | |
ParallelWritingWithApp.main(Array(id, i.toString)) | |
Console.err.println(s"read $id") | |
Source.fromFile(id).getLines().map(_.toInt).sum | |
}.zipWithIndex | |
} | |
println(maxes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment