Java Notes
Chapter 5 – Multithreading & Concurrency
Multithreading in Java allows simultaneous execution of two or more threads for maximum
utilization of CPU. Concurrency ensures correct, safe execution when multiple threads access
shared resources.
1. What is a Thread?
A thread is a lightweight subprocess. It has its own stack and shares memory with other threads
inside a process.
2. Thread Lifecycle
States: New → Runnable → Running → Blocked/Waiting → Terminated.
3. Creating Threads
Threads can be created by extending Thread class, implementing Runnable, or using lambda
expressions.
4. Synchronization
To prevent race conditions, synchronized blocks ensure that only one thread enters a critical
section.
5. Deadlock
When two threads wait on each other forever, the program freezes. Avoid lock ordering issues.
6. ExecutorService
Thread pools provide better performance and manageability than manually creating threads.
MCQs
• 1) Which method starts a thread? A) run() B) start() → Answer: B
• 2) Which framework supports thread pools? A) Executors B) Math → Answer: A
• 3) What is race condition? A) Data conflict in shared access B) A type of race → Answer: A
• 4) Thread lifecycle ends at? A) Terminated B) Waiting → Answer: A
Quick Summary
• Multithreading increases responsiveness and CPU utilization. • Concurrency issues like race
conditions must be handled. • Use ExecutorService for scalable thread management. • Always
avoid deadlocks by proper lock ordering.