Java MultiThreading means, executing multiple Processes concurrently. This is used to run Complex problems in Background without waiting for the main program. Multithreads use the Shared memory area. They don't allocate the separate memory for the process because of that reason we can save the memory and also this leads to improved performance and responsiveness in applications.

Advantages of Using Multi Threads

  • This is not blocking the users. Because threads are independent and users can perform multiple operations at the same time.
  • This helps to save the Time.
  • Threads are independent. If any exception occurs , It doesn’t affect the other threads.
  • Context switching between threads is usually cheaper than switching between processes..

Multitasking

Multitasking means executing multiple tasks simultaneously. This helps to utilize the CPU. We can achieve this multitasking in two ways.

  1. Process Based Multitasking
  2. Thread Based Multitasking

Process Based Multitasking.

  1. Every process has a separate memory address.
  2. Processes are relatively resource-intensive(heavyweight).
  3. Communication between processes can be expensive.
  4. Switching from one process to another process takes some time.

Thread Based Multitasking.

  1. Threads share the same memory address.
  2. Thread is a lightweight
  3. Communication between Thread can not be expensive.

Thread in Java.

Thread is a lightweight sub process which runs complex problems in the background without waiting for the main program. Thread has a separate path of execution. Threads used a shared memory area. Java provides Thread class to run our complex problems in the background. This provides some methods to create Threads and perform our operations.