Backend Development 14 min read

Analyzing a JDK ConcurrentLinkedQueue Memory Leak Bug in Jetty's QueuedThreadPool

This article examines a JDK bug causing memory leaks in Jetty's QueuedThreadPool due to improper removal in ConcurrentLinkedQueue, demonstrates the issue with a long‑running demo, analyzes heap growth using jconsole, VisualVM and jmc, and shows how newer JDK versions fix the problem.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
Analyzing a JDK ConcurrentLinkedQueue Memory Leak Bug in Jetty's QueuedThreadPool

The author begins with a personal anecdote before diving into a technical deep‑dive of a JDK bug (bug_id=8137185) that triggers memory leaks when Jetty's QueuedThreadPool uses ConcurrentLinkedQueue (CLQ) as its work queue.

The root cause is that the remove() method of CLQ does not unlink a node whose value has been set to null , leaving the node linked in the list and preventing garbage collection. This leads to gradual memory growth and increasingly slow queue operations.

A demonstration program repeatedly calls queue.add(obj) and queue.remove(obj) in a tight loop. When run on JDK 1.7.0_71, the demo shows the duration between iterations growing dramatically, the queue size staying at 1, and heap usage climbing until an OOM occurs after about 61 hours. The same demo on JDK 1.8.0_212 runs quickly with stable timings and no memory leak.

The article uses three monitoring tools—jconsole, VisualVM, and jmc—to visualize the heap usage trend, confirming the classic upward‑sloping memory‑leak pattern. Heap dumps reveal that CLQ nodes occupy over 94% of the retained heap.

Later JDK releases (7, 8, 9) include a fix that adds an unlink operation at the end of remove() , eliminating the leak. The author shows the patched source and notes that the issue is fully resolved in JDK 1.8.0_212 and later. Recommendations include using newer JDK versions, monitoring long‑running services with the mentioned tools, and being aware of similar concurrency bugs.

JavathreadpoolJDKMemoryLeakJettyConcurrentLinkedQueue
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

0 followers
Reader feedback

How this landed with the community

login 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.