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

TCS Java Interview | Java | Spring Boot | Microservices | Database

TCS Java Interview | Java | Spring Boot | Microservices | Database This post is based on a Java backend developer interview simulation and provides direct transcript-based answers to help you prepare for similar interviews. 📺 This interview scenario was inspired by a video from the  YouTube channel:  CloudTech . 🔗 Watch the full video here:  https://www.youtube.com/watch?v=yVj2EgwZxk4 1. Can you introduce yourself and talk about your tech stack and domains? I have around 4.5 years of experience working as a Java developer. My core expertise is in Java and developing REST APIs using Spring Boot. I also have basic knowledge of microservices architecture. On the database side, I work with SQL and Oracle. Additionally, I have exposure to UI technologies like Angular, HTML, and CSS, but they are secondary skills. My primary focus is backend Java development. 2. Which version of Java are you currently working on? We are currently using Java 8 but are in the process of upgr...

Top 20 Spring Boot Microservices Architecture Interview Questions (With Speakable Answers)

Top 20 Spring Boot Microservices Architecture Interview Questions (With Speakable Answers) * * * 1. What is Microservices Architecture?   → Microservices architecture breaks an application into small, independent services. Each one handles a specific business function and can be developed, deployed, and scaled independently. They usually communicate over REST APIs or messaging queues. * * * 2. How does Spring Boot help in building microservices?   → Spring Boot offers embedded servers, auto-configuration, starter templates, and production-ready tools. It works well with Spring Cloud to provide service discovery, config management, load balancing, and more. * * * 3. What are the core components in a microservices setup?   → Key components include:   ✓ API Gateway   ✓ Eureka (Service Discovery)   ✓ Config Server   ✓ Kafka or RabbitMQ   ✓ Circuit Breaker (like Resilience4j)   ✓ Centralized logging and monitoring (ELK, Prometheus) * * * 4. What i...

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. ...