Crash Isolation: Process Safety
You'll learn why a crashing process protects other processes, while a crashing thread can take down your entire application.
When designing concurrent systems, understanding crash boundaries is critical for building resilient applications.
How Crash Isolation Works
Processes are completely isolated by the operating system. Each process has its own memory space, file handles, and execution context. If one process crashes—whether from a segmentation fault, uncaught exception, or other fatal error—the operating system simply terminates that process. Other processes continue running unaffected because they don't share memory or resources.
Threads, however, all live within the same process. They share the same heap memory, static variables, and file descriptors. When a thread encounters an unrecoverable error (like an OutOfMemoryError or a severe JVM issue), it typically terminates the entire process. Even a thread throwing an uncaught exception can potentially destabilize the shared JVM environment, though Java's thread exception handlers can mitigate this in many cases.
The Safety Trade-off
Think of processes like separate buildings: if one building collapses, the others remain standing. Threads are like rooms in the same building: a fire in one room can spread and destroy the entire structure.
This is why microservices architectures favor separate processes for critical components—a crash in one service doesn't bring down the entire system. Within a single application, however, threads are preferred for their lightweight nature, but you sacrifice isolation for performance.
In Java, this means unhandled errors in threads (especially daemon threads or threads in thread pools) require careful exception handling and monitoring to prevent unexpected process termination.
Key Takeaway:
Processes provide crash isolation—one fails independently. Threads share fate—one can doom them all. Choose your concurrency model based on your fault tolerance requirements.