In this chapter, we will look at the java.lang.Thread class and see what it can do for concurrency and program performance in general.
Using the basic element of concurrency – thread
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 or 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 abstract method, run().
There are two ways to create a new thread: creating a subclass of Thread, or implementing the Runnable interface and passing the object of the...