Zeek_69_Multiprocessing And Multithreading in Java

 

What is a thread in Java?

A thread is a lightweight sub-process, the smallest unit of processing.

Why are multiprocessing and multithreading used in Java?

Multiprocessing and multithreadingboth are used to achieve multitasking.

Multitasking(It is the concurrent execution of multiple tasks over a certain period of time.)


What is multithreading and multiprocessing in Java and     which one is more convenient?

Multithreading  is a programming language concept in which a program or process is divided into two or more subprograms that are executed at the same time in parallel.

In other words

 Multithreading is a program execution technique that allows a single process to have multiple code segments (like threads). 

Whereas....

Multiprocessing refers to using multiple CPUs/processors in a single system.

 Multiple CPUs can act in a parallel fashion and executes multiple processes together. 

They increase computing power to a great extent

Symmetric multiprocessing and asymmetric multiprocessing are two types of multiprocessing.

..................................................................................................................................................

However, we use multithreading usually more than multiprocessing because threads use a shared memory area. They don't allocate separate memory area so saves memory, and context-switching between the threads takes less time than process.

Java Multithreading is mostly used in games, animation, etc.


Multitasking


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


1) Process-based Multitasking (Multiprocessing)

  • Each process has an address in memory. In other words, each process allocates a separate memory area.
  • A process is heavyweight.
  • Cost of communication between the process is high.
  • Switching from one process to another requires some time for saving and loading registers
    , memory maps, updating lists, etc.

2) Thread-based Multitasking (Multithreading)

  • Threads share the same address space.
  • A thread is lightweight.
  • Cost of communication between the thread is low.



Comments

Popular posts from this blog

Zeek_31_MethodInJava.java