Repaso
Español
Java CoreAdvancedJV-35

What does a "stop-the-world" pause in garbage collection mean, and how do modern collectors reduce it?

Options

  1. The program is stopped forever and has to be restarted
  2. All app threads pause during GC; G1 and ZGC shorten it (Correct option)
  3. The GC stops the operating system for a short time
  4. It only happens when System.gc() is called by hand

Answer

All application threads are paused while the GC works; collectors like G1 and ZGC do most work concurrently or in small regions to keep pauses short

Why

To safely move or free objects, the GC sometimes needs every application thread to pause. That pause is called stop-the-world. Long pauses make a service freeze (high latency spikes).

G1 (default since Java 9) splits the heap into regions and collects the ones with most garbage first, aiming at a target pause time.

ZGC and Shenandoah do almost all work concurrently, with pauses of about a millisecond, even on very large heaps.

Tuning starts by measuring: GC logs (-Xlog:gc), not by guessing flags.

Remember

Pause = threads frozen for GC. G1/ZGC aim for short pauses.

Key terms

Practice this question in Repaso