# Finding Java Thread Leaks With JDK Flight Recorder and a Bit Of SQL

DevFeed: [Finding Java Thread Leaks With JDK Flight Recorder and a Bit Of SQL](<https://devfeed.tech/articles/finding-java-thread-leaks-with-jdk-flight-recorder-and-a-bit-of-sql-18819.md>)

Original publisher: [Read original article](<https://www.morling.dev/blog/finding-java-thread-leaks-with-jdk-flight-recorder-and-bit-of-sql/>)

Published: 2023-02-28T21:16:10Z

Content type: tutorial

Language: en

Sources: [Gunnar Morling](<https://devfeed.tech/sources/gunnar-morling.md>)

Topics: [JDK Flight Recorder](<https://devfeed.tech/topics/jdk-flight-recorder.md>), [Java](<https://devfeed.tech/topics/java.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [SQL](<https://devfeed.tech/topics/sql.md>)

Tags: [java](<https://devfeed.tech/tags/java.md>), [jdk](<https://devfeed.tech/tags/jdk.md>), [jdk-flight-recorder](<https://devfeed.tech/tags/jdk-flight-recorder.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [performance-analysis](<https://devfeed.tech/tags/performance-analysis.md>), [root-cause-analysis](<https://devfeed.tech/tags/root-cause-analysis.md>), [sql](<https://devfeed.tech/tags/sql.md>), [thread](<https://devfeed.tech/tags/thread.md>), [threads](<https://devfeed.tech/tags/threads.md>)

## AI overview

This article explains how to investigate Java thread leaks with JDK Flight Recorder. It describes why thread leaks can cause memory and CPU problems, why thread dumps are limited, and how JFR events can reveal changing thread counts and the source of newly created threads.

## Source excerpt

The other day at work, we had a situation where we suspected a thread leak in one particular service, i.e. code which continuously starts new threads, without taking care of ever stopping them again. Each thread requires a bit of memory for its stack space, so starting an unbounded number of threads can be considered as a form of memory leak, causing your application to run out of memory eventually. In addition, the more threads there are, the more overhead the operating system incurs for scheduling them, until the scheduler itself will consume most of the available CPU resources. Thus it's vital to detect and fix this kind of problem early on.