Como obter traço de pilha de uma função em java

Thread.currentThread().getStackTrace();
Pixel Freak