Java Tutorial · Revision notes
Java Multithreading
Multithreading lets a Java program run several independent paths of execution (threads) inside one process. This chapter explains threads, the thread lifecycle, ways to create threads, synchronization and inter-thread communication with wait, notify and notifyAll.
Quick revision
- Threads share heap; each has its own stack
- States: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED
- start() creates a thread; run() is a normal call; no restart
- Runnable preferred; Callable + Future for results; shutdown executors
- synchronized = mutual exclusion + visibility; count++ is not atomic
- wait/notify/notifyAll: in synchronized, with while loop; wait releases lock