Common Java Threading Interview Questions
Fast recall
Quick revision
Core answer
Whether you can answer the canonical threading questions by naming the trade-off (e.g., synchronized vs Lock, race condition, deadlock) with a concrete example — not just definitions.
Defining 'race condition' or 'deadlock' abstractly without a concrete scenario or the resolution (synchronization / lock ordering).
Know the canonical six: thread vs process, creating a thread, synchronized vs Lock, wait/notify vs await/signal, race condition, deadlock — name the trade-off and give an example.
Interview-ready guide
Interview answer
Java threading interviews tend to ask the same core questions.
Thread versus process: a process has its own memory space, while threads share a process's memory and are lighter. How to create a thread: extend Thread or implement Runnable, and prefer Runnable because it separates the task from execution.
Synchronized versus Lock: synchronized is built-in and automatic, the lock is released on exit or exception, where Lock, ReentrantLock, is explicit, supports tryLock with a timeout and fairness, and needs manual unlock in a finally block. Wait-notify versus await-signal: wait and notify are on Object and require holding the object's monitor, while await and signal are on a Condition tied to a Lock and offer multiple wait-sets.
Race condition: correctness depends on timing when threads share state without synchronization, fixed by synchronizing or using atomics like AtomicInteger. Deadlock: threads hold locks each other needs, circularly waiting, fixed by always locking in a consistent order. A strong answer names the trade-off and gives a concrete example, not just a definition.
Common Java Threading Interview Questions
Direct Answer
The most common Java threading interview questions are: (1) thread vs process (a process has its own memory; threads share a process's memory); (2) how to create a thread (extend Thread or implement Runnable; prefer Runnable); (3) synchronized vs Lock (synchronized is built-in and automatic; Lock is explicit, flexible, and supports tryLock/timeout); (4) wait/notify vs await/signal (wait/notify are on Object and need synchronized; await/signal are on Condition with a Lock); (5) what is a race condition (correctness depends on timing when threads share state without synchronization); (6) what is a deadlock (threads circularly waiting for each other's locks). A good answer names the trade-off and gives a concrete example.
Code Example
// (1) RACE CONDITION: two threads increment a shared counter unsafely.
int count = 0;
Runnable inc = () -> { for (int i = 0; i < 10000; i++) count++; };
Thread t1 = new Thread(inc), t2 = new Thread(inc);
t1.start(); t2.start(); t1.join(); t2.join();
// count is likely < 20000 — lost updates (count++ is read+add+write, not atomic).
// FIX: synchronize, or use AtomicInteger.
// (2) DEADLOCK: two threads each hold a lock the other needs.
Object a = new Object(), b = new Object();
new Thread(() -> { synchronized(a){ synchronized(b){ /* ... */ } } }).start();
new Thread(() -> { synchronized(b){ synchronized(a){ /* ... */ } } }).start();
// t1 holds a, waits for b; t2 holds b, waits for a -> deadlock.
// FIX: always lock in a consistent order (a then b).
Common Mistakes & Pitfalls
- Defining 'race condition' or 'deadlock' without a concrete example or the fix.
- Not knowing that Lock.unlock() must be in a finally block (synchronized releases automatically).
- Confusing wait/notify (Object + synchronized) with await/signal (Condition + Lock).
Check your understanding
Answer these without looking back at the article.
- What is the difference between a thread and a process (memory)?
- What is a race condition, and how do you fix it (synchronize / atomic)?
- What is a deadlock, and how do you prevent it (lock ordering)?
- What's the difference between synchronized and Lock (automatic vs explicit, tryLock)?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.