I want to generate the thread dump of my running application. However, when I do kill -3 PID, it generate the thread dump at the console of the running application.
I want to generate it to a file. I know I can run the application as ./run.sh > thread_dump or I can also use jstack utility to redirect it to file.
However, I do not want to use any of those. In another approach I redirected the complete output of my console to a file by:
File file = new File("out.txt");
FileOutputStream fos = new FileOutputStream(file);
PrintStream ps = new PrintStream(fos);
System.setOut(ps);
Now every output is written in out.txt. But still, when I do kill -3 , it writes the thread dump to console.
What am I missing in the third approach? Would anybody know, what class/source is called when kill -3 is called on a JVM, so that I can look how thread dump is exactly written on making a kill -3 request/command?