Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- /*
- import scala.concurrent.ExecutionContext
- import scala.io.{BufferedSource, Source}
- object ExecutionContextGlobal extends App {
- //val data: BufferedSource = Source.fromFile("Write.txt")
- //val iter: Iterator[String] = data.getLines()
- //val dataString: String = iter.next()
- //val strings: Iterable[String] = dataString.split(",")
- //println(strings.size)
- def execute(body: =>Unit) =
- ExecutionContext.global.execute()
- val iter: Iterator[String] = Source.fromFile("Write.txt").getLines()
- val dataString: String = iter.next()
- val strings: Iterable[String] = dataString.split(",")
- val ints: Iterable[Int] = for(num <- strings) yield {
- num.toInt
- }
- val separated: (Iterable[Int], Iterable[Int]) = ints.splitAt(ints.size / 2)
- var sum1 = 0
- var sum2 = 0
- execute{
- sum1 = separated._1.sum
- println(sum1 + sum2)
- }
- execute{
- sum2 = separated._2.sum
- println(sum1 + sum2)
- }
- Thread.sleep(30000)
- }
- */
- ///////
- /*
- object ThreadSleep extends App {
- def thread(body: =>Unit): Thread = {
- val t = new Thread {
- override def run() = body
- }
- t.start()
- t
- }
- val t = thread {
- Thread.sleep(1000)
- println("new thread running")
- Thread.sleep(1000)
- println("still running")
- Thread.sleep(1000)
- println("comopleted")
- }
- t.join()
- println("new thread joined")
- }
- */
- import java.util.concurrent.{ForkJoinPool, _}
- import scala.io.Source
- object MyProgram2 extends App {
- val executor = new ForkJoinPool
- executor.execute(new Runnable{
- def run() = println("This task run asynchronously, MyProgram2")
- })
- Thread.sleep(500)
- }
- object ExecutorServiceCreate extends App {
- val executor: ExecutorService = Executors.newFixedThreadPool(4)
- executor.execute(new Runnable {
- def run() = println("This task run asynchronously, ESCreate")
- } )
- executor.shutdown()
- executor.awaitTermination(60, TimeUnit.SECONDS)
- }
- /*
- object ExecutionContextGlobal extends App {
- def execute(body: =>Unit) = ExecutionContext.global.execute( new Runnable {def run() = body})
- for (i <- 0 until 32) execute {
- Thread.sleep(2000)
- println(s"Task $i completed")
- }
- Thread.sleep(10000)
- }
- */
- object ExecutionContextGlobal extends App{
- val iter: Iterator[String] = Source.fromFile("Write.txt").getLines()
- val dataString:String = iter.next()
- val strings: Iterable[String] = dataString.split(",")
- val ints: Iterable[Int] = for (num<-strings) yield{ num.toInt}
- val sep:(Iterable[Int], Iterable[Int]) = ints.splitAt(ints.size/2)
- sep._1
- sep._2
- println(ints.sum)
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement