O'Reilly logo

Learning Scala Programming by Vikash Sharma

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Locks and synchronization

We talked about threads in previous sections—we'll first try to create a few ourselves before discussing them further. Let's write some code for that:

object ThreadFirstEncounter extends App { 
 
  class FirstThread extends Thread { 
    override def run(): Unit = println(s"FirstThread's run!") 
  } 
 
  val firstThread = new FirstThread() 
  firstThread.start() 
 
  println(s"CurrentThread: ${Thread.currentThread().getName}") 
  println(s"firstThread: ${firstThread.getName}") 
 
} 

A few pointers for the preceding code:

  1. We simply created an object extending App to create the application entry point.
  2. We created a class named FirstThread that extends Thread, which is nothing but the same java.lang.Thread we talked about in the previous section. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required