Learn Multi threading and multitasking in java in few minutes

Bsc 033 Devaraj B
2 min readApr 23, 2021

I know how hard is to learn multi threading and multitasking in java, but here I am going to solve your problem by this simple article. First you guys should know about what is thread? and then we will see about multi threading, multi tasking, its differences and advantages and disadvantages of multi threading.

Thread:-

A thread is a lightweight sub process, the smallest unit of processing. It is a separate path of execution. Threads are independent. If there occurs exception in one thread, it doesn’t affect other threads. It uses a shared memory area. Now we move on to multi threading in java.

Multi threading :-

multi threading in java is a process of executing multiple threads simultaneously.

Multi-threading extends the idea of multitasking into applications where you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel.

The OS divides processing time not only among different applications, but also among each thread within an application.

Java Multi threading is mostly used in games, animation, etc.Multi threading enables you to write in a way where multiple activities can proceed concurrently in the same program.

Multitasking :-

Multitasking is a process of executing multiple tasks simultaneously. We use multitasking to utilize the CPU. Multitasking can be achieved in two ways:

  1. Process-based Multitasking (Multi processing)

2. Thread-based Multitasking (Multi threading)

1) Process-based Multitasking(multi processing)

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(Multi threading)

Threads share the same address space.

  1. A thread is lightweight.
  2. Cost of communication between the thread is low.

Difference between multi threading and multitasking.

Advantages of multi threading:-

  1. Enhanced performance by decreased development time, because threads are independent.
  2. You can perform many operations together, so it saves time.
  3. Better use of CPU resources.
  4. It doesn’t affect other threads while exception, because threads are independent.

multi threading does not provide you with benefits only, it also have some disadvantages.

  1. complex debugging and testing processes.
  2. overhead switching of context.

by conclusion, multi threading and multitasking in java is an essential part that every java developer should be aware of. It is very helpful in making the program efficient and reduces the usage of storage resources. It actually makes the CPU’s to be utilized optimally to perform well regardless of its complexity.I hope i did something for you to gain knowledge about multi threading and multitasking.

website:- https://www.tutorialcup.com/java

--

--