Medium👤 3-5 years👤 8-15 years 1 min read

How do you choose a garbage collector — Serial, Parallel, G1, ZGC or Shenandoah?

Asked inAmazonGoogleMicrosoft
#g1#parallel gc#zgc#shenandoah#gc selection#latency
Report issue

⚡ Short Answer

Parallel GC = max throughput, batch jobs (tolerates pauses). G1 = balanced default for most services (predictable pauses). ZGC/Shenandoah = very large heaps needing sub-millisecond pauses. Serial = tiny heaps/single core. Match the collector to your throughput-vs-latency goal.

Coffee Chat Question

Concept Made Simple

How do you choose a garbage collector — Serial, Parallel, G1, ZGC or Shenandoah?

🧠Mind Map Answer

Remember It Faster

Parallelthroughput, batch — big pauses OK
G1 (default)balanced, pause target -XX:MaxGCPauseMillis
ZGC / Shenandoahhuge heaps, ~sub-ms pauses
Serialsmall heap, single core

🔥What If?

Think Beyond the Expected

A low-latency API on a 64 GB heap has unacceptable G1 pauses — what do you try?

Switch to ZGC (or Shenandoah): concurrent collectors that keep pause times in the sub-millisecond range largely independent of heap size, trading some throughput/CPU. Then measure p99 latency to confirm the improvement.

😂Real World

Most services run G1 (the default since Java 9). Latency-critical, large-heap systems move to ZGC; throughput-bound batch jobs sometimes prefer Parallel. The choice is a deliberate latency/throughput trade-off.

🎯Interviewer's Expectation

Keywords they're listening for:

throughput vs latencyG1 default + pause targetZGC/Shenandoah for low pause/large heapParallel for batchmeasure to decide

⚠️Common Mistakes

  • Switching GCs without measuring
  • Using Parallel for latency-sensitive APIs
  • Assuming a GC change is free of CPU cost

Best Practices

  • Start with G1; change only with data
  • Pick by latency vs throughput goal
  • Validate p99 latency, not just averages

🔁Follow-up Questions

  • 1What does -XX:MaxGCPauseMillis actually do in G1?
  • 2What does ZGC trade for its low pauses?
  • 3How do you A/B test a GC change safely?

🧩Related Technologies

G1ZGCShenandoahParallel GCJFR

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: GC Tuning (JVM)
Interview question: "How do you choose a garbage collector — Serial, Parallel, G1, ZGC or Shenandoah?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.
Open inChatGPTGeminiClaude

Was this answer helpful?

Support our platform by exploring our recommended products.

As an Amazon affiliate, purchases through these links may earn us a small commission — at no extra cost to you. It helps keep Full Stack Interview Guru free.

Related Questions