Why Does Java Service Load Spike on Startup? Uncover C2 CompilerThread Impact & Fixes

When a Java service starts, load can surge dramatically due to C2 CompilerThread activity, causing high response times, but by pre‑warming, increasing compiler threads, or using tiered compilation the spike can be mitigated and overall performance improved.

Programmer DD
Programmer DD
Programmer DD
Why Does Java Service Load Spike on Startup? Uncover C2 CompilerThread Impact & Fixes

Problem Description

During the deployment or restart of an online service (Jetty8 as the server), some machines experience a load spike up to 70 that lasts for about five minutes, and the response‑time curve mirrors the load curve.

Load spike during publish
Load spike during publish
Response time spike
Response time spike

Investigation Method

Monitor resource usage during publishing.

1) Use top -H -p to find high‑CPU threads; threads 2129 and 2130 show high usage.

High‑CPU thread list
High‑CPU thread list

2) Use jstack to dump stack information, convert thread IDs to hexadecimal (2129 → 851, 2130 → 852) and identify them as compiler threads (see Table 1).

"C2 CompilerThread1" daemon prio=10 tid=0x00007fce48125800 nid=0x852 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"C2 CompilerThread0" daemon prio=10 tid=0x00007fce48123000 nid=0x851 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None

Explanation of the Phenomenon

At startup, Java runs in interpreted mode, which is slow and causes high load and response times. As traffic flows, frequently executed methods are compiled by the C2 CompilerThread, increasing its CPU usage. Once compilation finishes, the thread’s CPU usage drops, performance improves, and load decreases.

The root cause is the prolonged compilation‑optimization phase, which creates the observed jitter.

Solutions

1) Warm‑up

Complete compilation before receiving real traffic. Two approaches:

Programmatic warm‑up: after startup, invoke hot code paths so they are compiled (verify with -XX:+PrintCompilation).

Traffic replay: use tools like tcpcopy to replay production traffic for warm‑up.

2) Increase compiler threads

Use the -XX:CICompilerCount flag to raise the number of compiler threads (default 2) to, for example, 4.

3) Use multi‑level compilation

HotSpot offers three compilation modes:

Client mode – lightweight, fast trigger, lower optimization.

Server mode – higher optimization, slower trigger (default for the service).

Tiered mode – starts with Client, then switches to Server, combining fast start‑up with high final performance. Enable with -XX:+TieredCompilation (default in Java 8).

Performance comparison of compilation modes
Performance comparison of compilation modes

Result Analysis

Applying warm‑up (solution 1) together with multi‑threaded compilation (solution 2) and tiered mode (solution 3) reduced load spikes dramatically. After several deployments, most machines stayed within a load range of 2–4, and spikes above 10 were rare. The combined approach shortens the jitter duration and improves overall stability.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaJVMperformanceCompilerThreadLoadSpike
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.