Thread in Scala Programming Language

  • date 8th October, 2020 |
  • by Prwatech |
  • 0 Comments

Life cycle of Thread:

Run

Runnable

Running

Block

Sleep()

Terminate

Thread Class

An Example of MultiThreading:

package Multi_thread

class MultiC1 extends Thread{

    override def run():Unit = {
        println(“Thread is running”)

    }
}

object Mu{
    def main(args: Array[String]): Unit = {
        val m = new MultiC1()
        m.start()
    }
}

Another Program for Multithreading

package Multi_thread
class MultiT2 extends Runnable{

    override def run(): Unit = {

      println("This Thread is Running and Implemented from Trait")

    }
}

object Mul{

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

     val m1 = new MultiT2()

     val e = new Thread(m1)

     e.start()

  }

}

Quick Support

image image