Multithreading
Multithreading is simply the synchronous execution, or concurrent execution, of two or more parts of a program, and it is a fundamental aspect of Java’s concurrent programming mechanism. We execute multiple parts of our programs, taking advantage of multi-core Central Processing Unit (CPU) resources to optimize the performance of our applications.
Before we get too far into multithreads, let’s focus on a single thread. In Java, a thread is a finite unit of execution within a method, function, or process. The Java Virtual Machine (JVM) handles the management of our threads. As you can see in the following code snippet, we extend the Thread
class to create and start threads:
class MyThread extends Thread { public void run() { System.out.println("Thread executed by extending Thread class."); } } /...