Java Threading
Introduction to multithreading in Java.
Concurrency is the generic term for two or more things happening at the same time.
Multitasking
Multitasking is the technique of performing numerous activities at the same time to maximize the CPU’s efficiency.[1]
There are two ways for multitasking. Process-based Multitasking (Multiprocessing) and Thread-based Multitasking (Multithreading).[1]
We use multithreading than multiprocessing because threads use a shared memory area. They save memory by not allocating separate memory regions, and context switching between threads takes less time than processing.[1]
Multithreading
In Java, multithreading is the process of running several threads at the same time. A thread is the smallest unit of processing and is a lightweight sub-process. [1]
Multithreading vs multiprocessing
As shown in Figure 1; there are multiple processes, multiple threads inside those processes, and each thread requires at least one process.[1]