248. Categorizing garbage collectors
Garbage collectors have evolved exactly as Java itself has evolved. Today (JDK 21), we distinguish between several GC types, as follows:
- Serial garbage collector
- Parallel garbage collector
- Garbage-First (G1) collector
- Z Garbage Collector (ZGC)
- Shenandoah Garbage Collector (not generational)
- Concurrent Mark Sweep (CMS) collector (deprecated)
Let’s tackle the main aspects of each GC type.
Serial garbage collector
The serial garbage collector is an STW single-threaded generational collector. Before running its own algorithms, this GC freezes/pauses all the application threads. This means that this GC is not suitable for multi-threaded applications such as server-side components. However, being focused on a very small footprint (useful for small heaps), this collector is a good fit for single-threaded applications (and single-processor machines) that can easily accommodate and tolerate...