Skip to main content
InterviewHubPRO
Section Overview
Q40

Question 40 of 50

Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)

80%
Kotlin & Coroutines (50 Qs)•Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)

Structured Concurrency & Exception Handling: `Job` vs `SupervisorJob` and cancellation propagation.

senior LevelPerformance

In Simple Words:

  • Standard Job: Follows strict cascading cancellation. If child coroutine A throws an unhandled exception, it immediately cancels its parent, which in turn cancels all sibling coroutines!
  • SupervisorJob: Isolates child failures. If child A crashes, child B and the parent continue executing unaffected.
    • Essential for Android ViewModels (viewModelScope uses SupervisorJob) so one failed network request does not crash the entire screen.
  • Cooperative Cancellation: Coroutines must cooperate with cancellation by periodically checking isActive or calling cancellable functions (delay, yield).