Preparing for Java and Spring Boot Interview?

Join my Newsletter, its FREE

3 Difference between multi-threading and multitasking? [Answered]

Hello guys, what is the difference between multithreading and multitasking is a common Java interview questions. If you are also wondering what it the real difference between them as they sound similar the continue reading this article and you will find the answer. In the programming world, there are two main ways to improve the throughput of a program,  by using multi-threading and by using multitasking. Both take advantage of parallelism to efficiently utilize the immense power of the CPU and improve the throughput of your program. Actually, multi-threading is nothing but thread-based multitasking. 

Since the difference between multi-threading and multi-tasking is an important fresher programming interview question and also often ask in viva or oral exams on computer science graduation courses, I thought to jot down a couple of important points together.

This article is the result of those points and can be handy when you quickly want to know the key difference between multi-threading and multi-tasking in concurrent programming.

Difference between multithreading and multi-tasking

Here are the key difference between multithreading and multi-tasking, you can note down and understand this point for interviews:

1. In multitasking, several programs are executed concurrently like Java compiler and a Java IDE like Netbeans or Eclipse, while in multi-threading multiple threads execute either the same or different parts of the program multiple times at the same time.

2. Multi-threading is more granular than multi-tasking. In multitasking, the CPU switches between multiple programs to complete their execution in real-time, while in multi-threading CPU switches between multiple threads of the same program. 

Remember, switching between multiple processes has more context switching cost than switching between multiple threads of the same program.

3. Processes are heavyweight as compared to threads, they require their own address space, which means multi-tasking is heavy compared to multithreading. Inter-process communication is expensive and limited and context switching from one process to another is expensive and limited.  See the difference between a Process and a Thread to learn more.
Here is the summary of the difference between multitasking and multithreading in concurrent programming:

Difference between multithreading and multitasking

That's all about the difference between multitasking and multithreading. Both are used to parallelize things in order to take full advantage of expensive hardware and CPU.  Multitasking is an ability of a computer to execute multiple programs at the same time while multi-threading is the ability of a process to execute multiple threads at the same time.  Sometimes multitasking is useful and other times multi-threading.

Related Java multi-threading Interview Questions from Java
  • How to join multiple threads in Java? (answer)
  • How to stop a thread in Java? (answer)
  • How to pause a thread in Java? (answer)
  • 5 differences between the wait() and sleep() method in Java? (answer)
  • Difference between notify() and notifyAll() in Java? (answer
  • How to avoid deadlock in Java? (answer)
  • Understanding the flow of data and code in Java program (answer)
  • Difference between wait() and yield() method in Java? (answer)
  • Difference between CyclicBarrier and CountDownLatch in Java? (answer)
  • What is the difference between the yield() and sleep() methods in Java? (answer)
  • How to do inter-thread communication in Java using wait-notify? (answer)
  • 5 Courses to Learn Java Multithreading in-depth (courses)
  • Difference between atomic, volatile, and synchronized in Java? (answer)
  • 10 Advanced books for Experienced Programmers (books)
  • 50+ Thread Interview Questions for Beginners (questions)
  • What is happens before in Java Concurrency? (answer)

Thanks for reading this article, if you like this tutorial then please share it with your friends and colleagues. If you have any questions or feedback then please drop a comment. 

No comments:

Post a Comment

Feel free to comment, ask questions if you have any doubt.