← Recipes

Throughput Batch Job

Favor total work completed over pause consistency for batch-style processes.

Flags

-XX:+UseParallelGC-Xms-Xmx

-XX:+UseParallelGC selects a throughput-oriented collector. It can pause the application for collection work, but it is often efficient for CPU-bound batch jobs that are judged by total runtime.

Flag details

-XX:+UseParallelGC
Selects the Parallel collector, which uses multiple GC worker threads and prioritizes total throughput over low pause times.
-Xms8g -Xmx8g
Gives the batch job a fixed 8 GB heap so the JVM does not spend time growing the heap while processing the workload.
-Xlog:gc*
Records full and young collections so you can compare total GC time with total job duration.

How Parallel GC works

Parallel GC uses stop-the-world young and old generation collections with multiple worker threads. During a collection, application threads are paused while GC threads reclaim memory. This makes individual pauses longer than low-latency collectors, but the collector can be efficient when the goal is maximum work completed per unit of time.

This fits batch jobs because there is usually no interactive user waiting on a single request. The right measurement is often wall-clock completion time, not the longest pause.

When to use it

Use this for ETL, offline indexing, large imports, compilers, test suites, and report generation when no user is waiting on an individual request.

Java version support

Parallel GC and -Xms/-Xmx are longstanding HotSpot options and apply across all cataloged Java versions. The -Xlog:gc* form is Java 9+; Java 8 uses legacy GC logging flags.

Related JEPs

Examples

java -XX:+UseParallelGC -Xms8g -Xmx8g \
  -Xlog:gc*:file=logs/batch-gc.log:time,uptime,level,tags \
  -jar batch.jar

Use this for repeatable benchmark-style runs with the same input size.

java -XX:+UseParallelGC -Xmx16g \
  -jar indexer.jar --rebuild

Use a larger max heap when the job benefits from fewer collections and memory is available.

Verify

Measure wall-clock completion time, CPU utilization, and total GC time across repeated runs with the same input.