Sunday, 20 August 2017

What Is Multithreading in Java

What Is Multithreading in Java

Multithreading in java is a process of executing multiple threads simultaneously.

Advantages of Java Multithreading
1) It doesn't block the user because threads are independent and you can perform multiple operations at same time.

2) You can perform many operations together so it saves time.

3) Threads are independent so it doesn't affect other threads if exception occur in a single thread.

Multitasking
Multitasking is a process of executing multiple tasks simultaneously. We use multitasking to utilize the CPU. Multitasking can be achieved by two ways:
  • Process-based Multitasking(Multiprocessing)
  • Thread-based Multitasking(Multithreading)

1) Process-based Multitasking (Multiprocessing)
  • Each process have its own address in memory i.e. each process allocates separate memory area.
  • Process is heavyweight.
  • Cost of communication between the process is high.
  • Switching from one process to another require some time for saving and loading registers, memory maps, updating lists etc.
2) Thread-based Multitasking (Multithreading)
  • Threads share the same address space.
  • Thread is lightweight.
  • Cost of communication between the thread is low.

Post a Comment

Whatsapp Button works on Mobile Device only

Start typing and press Enter to search