https://github.com/kagkarlsson/threaddump-demo
Spring web-app which can simulate different types of slow requests. Intended for experimenting with threaddumps
https://github.com/kagkarlsson/threaddump-demo
java jvm performance threaddump
Last synced: 5 months ago
JSON representation
Spring web-app which can simulate different types of slow requests. Intended for experimenting with threaddumps
- Host: GitHub
- URL: https://github.com/kagkarlsson/threaddump-demo
- Owner: kagkarlsson
- Created: 2023-04-11T11:43:34.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-12T06:28:39.000Z (almost 3 years ago)
- Last Synced: 2025-07-08T03:04:15.395Z (7 months ago)
- Topics: java, jvm, performance, threaddump
- Language: Java
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Thread-dump demo application
This is an example Spring web-app which can simulate different types of slow requests. It is intended
to be used for experimenting with threaddumps.
## Exercise
1. Start the `ThreaddumpDempApplication` using your IDE or mvn
```shell
mvn spring-boot:run
```
2. Trigger the scenario you want to test. Example scenario `database_read` here:
```shell
curl http://localhost:8080/fakework/database_read
```
3. Take the thread-dump, for example using `jcmd` (`| less` makes it easier to browse/search). You have 20s.
```shell
jcmd no.bekk.threaddumpdemo.ThreaddumpDemoApplication Thread.print | less
```
4. Find and inspect the relevant thread to see what the stack looks like for that particular scenario.
**Hint:** search for packages specific for this app, e.g. `no.bekk.threaddumpdemo`
## Alternative ways to get a thread-dump
**Hint:** Use a no-arg `jcmd` to list pids and classnames for running java-processes (might not work in some envs).
```shell
jstack
jcmd Thread.print
jcmd Thread.print
# If no JDK, SIGQUIT dumps threads to System.out
kill -QUIT
# For a Kubernetes pod (Java pid is typically 1)
kubectl exec -- jstack 1
```
## Scenarios
```
curl http://localhost:8080/fakework/
```
* `database_read` - Slow database-query
* `tcp_connect` - Tcp-connect does not complete before timeout
* `http_client_get` - Slow third-party webservice
* `db_pool_get_connection` - Forced to wait for connections as pool all connections occupied
* `lock_contention` - Forced to wait for lock held by another thread
* `cpu_loop` - Slow local loop (i.e. pure cpu)
## Thread states
- `RUNNABLE` - thread is currently executing/can be executed in the jvm
- `BLOCKED` - thread is blocked indefinitely while waiting for a lock (typically synchronized)
- `TIMED_WAITING` - thread is waiting for a period of time (triggered by e.g Thread.sleep(..))
- `WAITING` - thread is waiting indefinitely for another thread to perform a certain action (i.e. Object.wait()->Object.notify, ...)
## Resources
* [https://www.baeldung.com/java-thread-dump](https://www.baeldung.com/java-thread-dump)
* [https://www.baeldung.com/java-analyze-thread-dumps](https://www.baeldung.com/java-analyze-thread-dumps)