What is Multithreading? Explain how Java supports programming for multitasking environment.A thread is one of the processes of an application. In multithreading, an OS allows different threads of an application to run in parallel.
The multitasking environment can execute in two ways.
1. Process based multitasking
2. Thread based multitasking
Process based multitasking – Process based multitasking is when two different processes, running at different locations, execute simultaneously.
Example: A user can write some text using editor and simultaneously play music.
Thread based multitasking – A thread is the smallest unit of a dispatchable code.
Two different tasks like printing a document and editing it simultaneously can be done in a thread based multitasking environment.
Threads can be implemented in Java using the Thread Class.
The threading concept says that the different blocks of the same program can be executed concurrently.