Scala – Thread

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

A Thread is a lightweight sub-measure possessing less memory. To make it, we can either expand the Thread class or the Runnable interface. We can utilize the run() method at that point. A thread holds less memory than an entire process.

 

Use case 1:

Scala thread example by extending Thread Class

class thread extends Thread {
  override def run(){  
println("Thread is running...");  
}  
}  
object MainObject{  
def main(args:Array[String]){  
var t = new thread()  
t.start()  
}  
}
Output:
Thread is running...

Use case 2:

Scala Thread Example by Extending Runnable Interface

class thread extends Runnable {
  override def run(){  
println("Thread is running...")  
}  
}  
object MainObject{  
def main(args:Array[String]){  
var e = new thread()  
var t = new Thread(e)  
t.start()  
}  
}
Thread is running...

 

Quick Support

image image