Skip to content

Commit b806abd

Browse files
NadaharRavi Nadahar
andauthored
Document how to make thread dumps (#2628)
* Document how to make thread dumps Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com> * Fix typo Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com> --------- Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com> Co-authored-by: Ravi Nadahar <nadahar@rediffmail.com>
1 parent 414c946 commit b806abd

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

administration/runtime.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,72 @@ Created dump zip: 2025-08-08_171434.zip
182182

183183
You will find this ZIP in the `$OPENHAB_USERDATA` folder, usually `/var/lib/openhab/` on Linux systems.
184184

185+
::: tip Note
186+
The thread dumps created from Karaf lack some important information for troubleshooting blocked threads.
187+
See alternative ways to create thread dumps below if that is the intended use.
188+
:::
189+
185190
Please refer to the [Karaf Developer Commands documentation](https://karaf.apache.org/manual/latest/#_developer_commands) for more information about all available commands.
191+
192+
## Thread Dumps
193+
194+
Thread dumps capture the state of all JVM threads and are essential when diagnosing high CPU usage, deadlocks or blocked threads.
195+
Below are several methods to produce thread dumps.
196+
197+
### Java Process Identifier
198+
199+
The command line tools described here require the process identifier (PID) of the Java process as an argument.
200+
To find the PID, open a command console and run one of the following commands:
201+
202+
```shell
203+
ps u -C java # Linux
204+
ps aux | grep java # macOS/Linux
205+
tasklist /FI "IMAGENAME eq java.exe" # Windows
206+
```
207+
208+
Sometimes, more than one entry is returned, and it might not be obvious which one is openHAB. In most situations it will either only be one entry, or it will be obvious which one is openHAB.
209+
210+
### Using `jstack`
211+
212+
`jstack` is part of the JDK and prints a full thread dump from a running JVM.
213+
Required privileges will usually be `root`/`administrator`: prefix with `sudo` on Linux and macOS, use an elevated command prompt on Windows.
214+
215+
This command will create a new file called `threaddump.txt` in the current directory, which contains the thread dump information:
216+
217+
```shell
218+
jstack -l <PID> > threaddump.txt
219+
```
220+
221+
`jstack` is located in the JDK `bin` directory.
222+
223+
### Using `jcmd`
224+
225+
`jcmd` is another JDK tool that can trigger many diagnostic actions.
226+
It also usually requires `sudo` (Linux/macOS) or elevated command prompt (Windows).
227+
228+
This command will create a new file called `threaddump.txt` in the current directory, which contains the thread dump information:
229+
230+
```shell
231+
jcmd <PID> Thread.print -l > threaddump.txt
232+
```
233+
234+
### Using VisualVM / Java Mission Control
235+
236+
GUI tools such as [VisualVM](https://visualvm.github.io/) or [Java Mission Control (JMC)](https://www.oracle.com/java/technologies/javase/products-jmc9-downloads.html) can attach to a running JVM (local or remote with JMX) and provide thread dumps with additional visualization and analysis tools.
237+
Setting up remote access can be a bit of work and isn't covered here, so these tools are recommended only if openHAB is running on a computer with a desktop environment, but are excellent options when that is the case.
238+
239+
### Inside Containers and Remote Systems
240+
241+
For Docker containers, either exec into the container and run `jcmd`/`jstack`:
242+
243+
```shell
244+
docker exec -it <container> jcmd <PID> Thread.print -l
245+
```
246+
247+
For remote systems without SSH access to JDK tools, remote JMX can be configured and enabled to allow remote access from VisuaVM or Java Mission Control, but the details for doing this must be acquired elsewhere.
248+
249+
### Helpful Tips
250+
251+
- Always run diagnostic tools with appropriate privileges (e.g., `sudo` on Linux).
252+
- If you need to correlate a Java thread to an OS thread, look for the `nid` value in the thread dump (usually hex). Convert it to decimal to compare with `top`/`ps` thread ids.
253+
- If a thread dump is not enough, capture several dumps spaced a few seconds apart to see which stacks are consistently present (useful for intermittent CPU spikes).

0 commit comments

Comments
 (0)