Java Multithreading Interview Questions and Answers

Here, we have listed the most important and top Java multithreading interview questions with the best possible answers.

When you will go to any Java interview, senior or junior, experienced or freshers, Interviewer always asks a couple of questions from thread, concurrency, and multithreading.

He starts slowly from basic concepts of thread by asking questions like why need threads, how to create threads, which one is a better way to create threads, etc, and then goes for advanced questions.

Here, the list of top interview questions from basic to advanced from Java thread, concurrency, and multithreading. You can prepare well from the list of these Java thread interview questions.

Thread and Multithreading Interview Questions in Java with Answers


1. What is Thread in Java?

Ans: A thread is a single independent path of execution of a group of statements. It is used to perform more than one task simultaneously.

2. What is a process in Java?

Ans: A process is a program that executes as a single thread. A thread is a subset (part) of process. One process can contain multiple threads.

3. What is the difference between thread and process in Java?

Ans: The difference between a thread and a process is as follows:

  • A process is a program that is executing whereas, a thread is the smallest unit (piece) of executable code within a process.
  • A process can have more than one thread.
  • A process is considered as heavyweight while a thread is called lightweight.
  • Threads are easy to create but processes are not easy to create.
  • Threads within a process can communicate directly while processes do not communicate so easily because they need an operating system, files, or network to communicate.
  • Processes are heavily dependent on system resources available whereas threads need minimal amounts of resources.
  • Every individual process has its own separate memory address space but all threads share the same memory address space.

4. What is a single-threaded program and a multithreaded program?

Ans: When a program contains a single flow of control, it is called single-threaded program.

When a program contains multiple flows of control, it is called multithreaded program.

5. Which thread always runs in a Java program by default?

Ans: Main thread

6. Why threads are lightweight process in Java?

Ans: Threads are also known as lightweight because they can be executed in the same memory space. All the threads in the main application program share the same address space in the memory so that they can easily communicate among themselves.

Thus, they also take less space in memory and less processor time.

7. What is the use of threads in Java?

Ans: Threads can be used for multiple purposes. Some advantages of using threads are as follows:

  • Threads are mainly used in server-side programs where we need to handle multiple clients on network or internet simultaneously.
  • Another important use of threads is in creating games and animations.
  • Generally, threads can be used to perform more than one task simultaneously.


8. What is Multithreading in Java? Why it is needed?

Ans: The process of executing multiple threads simultaneously (concurrently) is called multithreading in Java.

Multithreading is needed because of the following reasons:

a) Multithreading makes the program more responsive and interactive.
b) It enhances the performance of the application.
c) Multithreaded programs can run faster than single-threaded programs in some cases even on single processor system.
d) It makes maximum utilization of CPU and keeping the idle time of CPU to minimum.

9. Explain the concept of context switching of thread.

Ans: The process of switching from one thread to another thread by CPU is called context switching.

10. Explain the time-sharing of thread in Java.

Ans: In a single processor system, multiple threads share CPU time that is known as time-sharing.

11. What are the advantages of Multithreading in Java?

Ans: The advantages of using multithreading programming concept are as follows:

  • Multithreading helps to reduce computation time.
  • Multithreading technique improves the performance of the application.
  • Threads share the same memory address space. Hence, it saves memory.
  • Multithreaded program makes maximum utilization of CPU and keeping the idle time of CPU to minimum.
  • Context switching from one thread to another thread is less expensive than between processes.
  • In a multithreaded application program, different parts of the application are executed by different threads. The entire application does not stop even if an exception occurs in any of the threads. It does not affect other threads during the execution of the application.

12. What are the drawbacks of multithreading in Java?

Ans: The drawbacks of multithreading in Java are as follows:

  • Increased complexity.
  • Synchronization of shared resources.
  • In the multithreading programming concept, debugging is difficult. At times, result is unpredictable.
  • Potential deadlocks.
  • Programming complications may occur.

13. How can multiple threads run in a single-processor system concurrently (simultaneously)?

Ans: In single-processor systems, multiple threads share the CPU time, known as time-sharing.


14. What is multitasking in Java? What are the two types of multitasking?

Ans: The process of executing one or more tasks concurrently or at the same time is called multitasking. It is the ability of an operating system to execute multiple tasks at once.

There are two types of multitasking or multitasking can be implemented in two ways:

  • Process-based multitasking (Multiprocessing)
  • Thread-based multitasking (Multithreading)

15. What is the difference between process-based multitasking (multiprocessing) and thread-based multitasking (multithreading)?

Ans: The difference between multiprocessing and multithreading are as follows:

1. The process of executing multiple programs or processes at the same time (concurrently) is called process-based multitasking or multiprocessing. 1. The process of using multiple threads to perform one or more tasks at the same time in a program by the processor is called thread-based multitasking.
2. In process-based multitasking, several programs are executed at the same time by microprocessor. 2. In thread-based multitasking, a program uses multiple threads to perform one or more tasks at the same time by a processor.

16. What are the advantages of thread-based multitasking over process-thread multitasking?

Ans: The main advantages of thread-based multitasking as compared to process-based tasking are:

  • Threads share the same memory address space.
  • Context switching from one thread to another thread is less expensive than between processes.
  • The cost of communication between threads is relatively low.
  • Threads are lightweight as compared to processes (heavyweight). They utilize the minimum resources of the system. They take less memory and less processor time.

17. What is the difference between single-tasking and multi-tasking?

Ans: When only one task is executed at a time, it is called single-tasking.

When several tasks are executed at a time, it is called multi tasking.

In single tasking, the CPU time is wasted, but we can utilize the CPU time in an optimum way in multi-tasking.

18. What are the ways to create a new thread in Java?
       or How do you implement thread in Java?

Ans: There are two ways to create or implement a new thread in Java. They are:

  • By extending Thread class: Extend the Thread class and override the run() method.
  • By implementing Runnable interface: Implement Runnable interface and implement the run() method.

19. When to use Runnable interface vs Thread class in Java? Which one is better?

Ans: Implement Runnable interface is better to use than extends Thread class because Java programming language does not support multiple inheritance through class, but it always supports multiple inheritance through the interface.

20. What is the difference between “extends Thread” and “implements Runnable” in Java?

Ans: extends Thread class and implements Runnable interface both have the same function. But when we extend Thread class, there is no scope to extend another class because Java does not support multiple inheritance through classes.