O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

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

Getting ready

A Java application starts as the main thread (not counting system threads that support the process). It can then create other threads and let them run in parallel (sharing the same core via time slicing of having a dedicated CPU for each thread). This can be done using the java.lang.Thread class that implements the Runnable functional interface with only one run() method. 

There are two ways of creating a new thread: creating a subclass of Thread or implementing the Runnable interface and passing the object of the implementing class to the Thread constructor. We can invoke the new thread by calling the start() method of the Thread class (which, in turn, calls the run() method that we implemented).

Then, we can either let the ...

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