Skip to main content

Top 15 Java Multithreading Interview Questions – With Real-Life Examples

Top 15 Java Multithreading Interview Questions – With Real-Life Examples




Multithreading is a powerful feature in Java that allows concurrent execution of two or more threads. It helps in maximizing CPU utilization and building high-performance applications. In backend interviews, especially for product-based companies, questions related to Java concurrency and multithreading are asked frequently. Here are 15 top multithreading questions with real-world examples and answers you must prepare for interviews in 2025.

1. What is the difference between a process and a thread?

Process: A process is an independent program in execution with its own memory space and resources.
Thread: A thread is a lightweight sub-process. Multiple threads of a process share the same memory and can communicate easily with each other.

2. How do you create a thread in Java?

There are two common ways:

// 1. Extending Thread class
class MyThread extends Thread {
    public void run() {
        System.out.println("Thread is running");
    }
}
new MyThread().start();

// 2. Implementing Runnable interface
class MyRunnable implements Runnable {
    public void run() {
        System.out.println("Runnable is running");
    }
}
new Thread(new MyRunnable()).start();

3. What is the lifecycle of a thread?

A thread goes through five states:

  • New: Thread is created but not yet started.
  • Runnable: Thread is ready to run and waiting for CPU.
  • Running: Thread is executing.
  • Blocked/Waiting: Thread is paused, waiting for resources or notification.
  • Terminated: Thread has finished execution or terminated due to error.

4. Difference between start() and run() methods?

start() creates a new thread and then calls run() internally. run() is a normal method and if you call it directly, no new thread is started – it runs on the main thread.

5. What is synchronization in Java?

Synchronization prevents thread interference and ensures that only one thread can access critical sections at a time. This avoids data inconsistency.

public synchronized void update() {
    // critical code
}

6. What is a deadlock in multithreading?

Deadlock is a situation where two or more threads wait for each other to release resources, and none proceeds. For example:

  • Thread A locks Resource 1 and waits for Resource 2.
  • Thread B locks Resource 2 and waits for Resource 1.

7. What is the use of volatile keyword in Java?

volatile ensures that changes made by one thread are visible to other threads. It prevents threads from caching variables locally.

8. What is the difference between synchronized and ReentrantLock?

synchronized is a keyword that is easier to use but less flexible. ReentrantLock is an advanced API that gives more control like tryLock(), lockInterruptibly(), fairness policies, etc.

9. What is thread starvation?

Starvation happens when low-priority threads are unable to gain CPU access because high-priority threads are continuously running.

10. How does thread communication work in Java?

Java provides wait(), notify(), and notifyAll() for thread communication.

synchronized (lock) {
    while (!condition) {
        lock.wait();  // waits until notified
    }
    // do something
    lock.notify();  // notifies one waiting thread
}

11. Difference between wait() and sleep()

  • wait() releases the monitor/lock while waiting; sleep() does not.
  • wait() must be used in synchronized blocks; sleep() can be used anywhere.

12. What are daemon threads?

Daemon threads are background threads that run in the background to provide services. They are terminated automatically when all user threads finish execution.

Thread t = new Thread(() -> {});
t.setDaemon(true);
t.start();

13. What is ThreadLocal in Java?

ThreadLocal provides thread-confined variables. Each thread using a ThreadLocal variable has its own, independently initialized copy of the variable.

ThreadLocal<Integer> threadLocal = ThreadLocal.withInitial(() -> 0);
threadLocal.set(100);  // this value is unique to the current thread

14. What is Callable and Future?

Callable is like Runnable but it can return a result and throw exceptions.
Future represents the result of an asynchronous computation.

ExecutorService executor = Executors.newSingleThreadExecutor();
Future<String> future = executor.submit(() -> "Result");
System.out.println(future.get()); // prints: Result

15. How to avoid concurrency issues in Java?

  • Use synchronized methods/blocks wisely
  • Use concurrent collections (like ConcurrentHashMap)
  • Use atomic classes (like AtomicInteger)
  • Use ThreadLocal to isolate state per thread
  • Design for immutability

Conclusion

Java multithreading is a must-know topic for backend interviews, especially when you’re targeting product companies or roles that require handling real-time traffic and scalability. These 15 questions cover everything from basic concepts to advanced interview scenarios.

Stay connected with InterviewYatra.com for more Java interview prep, real company questions, and backend system design content.

Comments

Popular posts from this blog

Top 15 React Interview Questions for 1–2 Years Experience

🟦 Top 15 React Interview Questions for 1–2 Years Experience Preparing for a React interview with 1–2 years of experience? Here's a carefully curated list of 15 important React questions with clear, real-world answers. These are frequently asked in interviews at companies like TCS, Infosys, Cognizant, Capgemini, and product-based firms. Q1. What is the Virtual DOM in React, and how does it improve performance? Answer: The Virtual DOM is a lightweight, in-memory copy of the real DOM. When state/props change, React creates a new Virtual DOM tree, compares it with the old one (diffing), and only updates the parts of the real DOM that changed. This makes rendering much faster and improves performance in large applications. Q2. What is JSX in React? Answer: JSX stands for JavaScript XML. It allows us to write HTML elements in JavaScript and place them in the DOM without using createElement() . JSX improves code readability and is transpiled to React.createElement() calls. ...

Top 15 Spring Boot Interview Questions and Answers – Real Examples (2025)

Top 15 Spring Boot Interview Questions – 2025 Spring Boot is one of the most demanded frameworks for Java backend development. Whether you're interviewing for TCS, Infosys, or a product-based company, these Spring Boot questions will help you prepare like a pro. Here are 15 questions with detailed explanations for developers with 1–2 years of experience. Q1. What is Spring Boot? Answer: Spring Boot is a Java-based open-source framework built on top of the Spring Framework. It helps developers create stand-alone, production-ready Spring applications with minimal configuration. Its key features include: Auto-configuration Embedded servers (Tomcat, Jetty) Starter dependencies Production-ready tools (Actuator, Metrics, etc.) Example: You can create a REST API within minutes by using @RestController and spring-boot-starter-web — no need for external web server deployment. Q2. What is the role of @SpringBootApplication annotation? Answer: This annotation i...

Wipro Java Developer Interview Questions with Answers (Mid-Level Role)

  Wipro Java Developer Interview Questions with Answers (Mid-Level Role) (Glassdoor Based – May 2024) Interview Location: Bengaluru Interview Mode: Online Candidate Role: Mid-Level Java Developer Source: Based on real experience shared on Glassdoor Review Summary: Easy and conversational. Interviewer was friendly. Focus was mainly on Java basics, internals, and real-world understanding. Q1: What is static in public static void main(String[] args) ? A: The static keyword lets the JVM call the method without creating an object. It indicates that the method belongs to the class, not instances. Q2: Why does a Java program start from the main method? A: main() is the predefined entry point of a Java application. The JVM starts execution from there. Q3: What are Checked and Unchecked Exceptions? With examples. A: Checked Exceptions : Detected at compile time. E.g., IOException , SQLException . Unchecked Exceptions : Detected at runtime. E.g., NullPointerExce...