World 19 of 26 · Advanced

🧵 Concurrency Fundamentals

14 Java concepts, each explained step by step with real code, a common trap and practice questions.

  1. Processes vs threadsThreads share heap memory within a process; each has its own stack.
  2. Creating threadsThread + Runnable, Thread.ofPlatform, start() vs run().
  3. Thread lifecycleNEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED.
  4. sleep, join & interruptCooperative cancellation, InterruptedException, restoring the interrupt flag.
  5. Race conditionscount++ is read-modify-write and not atomic.
  6. synchronizedIntrinsic locks on methods and blocks, mutual exclusion, reentrancy.
  7. Visibility & volatileCaching across cores; volatile guarantees visibility but not atomicity.
  8. The Java Memory Modelhappens-before rules: locks, volatile, thread start/join, final fields.
  9. DeadlockCircular waiting on locks, and lock ordering to prevent it.
  10. Livelock & starvationThreads busy but not progressing; unfair scheduling.
  11. wait / notifyCondition waiting inside synchronized, spurious wakeups, while-loop guard.
  12. Daemon threadsDaemon threads don't keep the JVM alive.
  13. Thread safety strategiesImmutability, confinement, synchronization, thread-safe classes.
  14. ThreadLocalPer-thread values and leak risks in pools.