Urgent.News

What's breaking now, across thousands of outlets.

Tech

What jstack Misses When Your Java Service Uses Virtual Threads

Take a Spring Boot service with virtual threads enabled, a HikariCP pool of 10 connections, and roughly 5,000 requests in flight. Latency is climbing. You grab a thread dump and find 43 platform threads, most of the scheduler workers waiting in ForkJoinPool.awaitWork , and very little CPU activity. If you used jstack , the requests you're looking for may never have made it into the file. On JDK…

When a Java service utilizes virtual threads, the traditional jstack tool may not accurately reflect the system's state, particularly if there are numerous requests in flight. For instance, consider a Spring Boot service with a HikariCP pool of 10 connections and around 5,000 requests in progress. Latency issues arise, and executing jstack yields 43 platform threads, primarily scheduler workers waiting in ForkJoinPool.awaitWork, with minimal CPU activity.

However, jstack fails to list virtual threads on JDK 21 through 25, making it difficult to identify the requests waiting for database access.

To capture virtual threads and their associated information, the jcmd command with the Thread.dump_to_file option can be used. This command has been available since JDK 21 and generates a text or JSON file containing thread stacks. Compared to jstack, jcmd provides additional details such as thread ID, name, a virtual marker, state, timestamps, and lock information in JDK 25. It also allows for capturing multiple virtual threads and their parent-child relationships, which can help identify the root cause of the bottleneck.

By analyzing the captured dump files, one can examine the thread stacks and identify the resources causing delays, such as HikariPool.getConnection(). For example, if each request holds a connection for approximately 18 milliseconds, ten connections could take around nine seconds to clear a backlog of 5,000 requests, assuming no new requests are arriving.

This information can guide further investigation into slow queries, transaction scope, and potential database performance issues. Ultimately, combining the dump analysis with system metrics can provide a comprehensive understanding of the performance issues and help optimize the service's resource utilization.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Boston College Men’s Hockey Falls to St Cloud State 5-3

The Boston College men’s hockey team dropped the second game of their weekend series with St. Cloud State on Saturday night, falling by a score of 5-3. The Eagles spent a lot of time in the penalty box throughout the game, continuing a bit of a concerining trend to start the season, and found themselves […]

Why your generated Anki image occlusion cards import as plain cloze (and the one-line fix)

I've been building AnkiForge , a web app that turns lecture PDFs and labelled diagrams into Anki cards. For diagrams it makes image occlusion cards: every label on, say, a heart diagram gets hidden…

  • Anki generates image occlusion cards from lecture PDFs and diagrams
  • Missing ORIGINALSTOCKKINDIMAGEOCCLUSION flag hides image occlusion button
  • Removing flag allows desktop UI to recognize cards as image occlusion

More from Sunday 18 October →