Multithreading and Garbage Collection

Multithreading allows programmers to write efficient programs that make the maximum use of the CPU.
Java provides built-in support for multithreading in the form of classes and interfaces.
When Java programs are executed, there is already one thread that is running and it is the main thread. This main thread is important for two reasons:
It is the thread from which child threads will be created.
Program is terminated when the main thread stops execution.
Thread objects can be created in two ways:
Declare the class to be a sub-class of the Thread class where we need to override the run() method of the Thread class.
Declare a class that implements the Runnable interface. Then define the run() method.
Each thread in a Java program is assigned a priority, and the Java Virtual Machine never changes the priority of a thread.