2 Java debugging tricks

1. Embed state in your thread names.

Some times when you see a crash log with a thread dump, you see the stack of all the threads at the moment of the snapshot, but there’s no way to see what the state of the variables and objects at play in the thread were like.

You can use Thread.currentThread.setName(...) and embed variable states on the thread name for a more useful thread dump output.

2. Set a Default uncaught exception handler and log the error to the thread.