How can I get all currently running threads in a batch file in java?
Asked
Active
Viewed 704 times
-1
-
See this post. http://stackoverflow.com/questions/1323408/get-a-list-of-all-threads-currently-running-in-java Possible dup. – Alec. Jun 05 '13 at 10:59
-
In batch file? Linux, bash, or what? Or is it really a Java question? Do you want to do it inside your java code? – Dariusz Jun 05 '13 at 11:14
-
yes in windows and yeah I want to do it in my java code – user2455242 Jun 05 '13 at 13:01
-
@AlecHenderson_v1.00 I have already tried this but it reads all the running threads in system but not in the batch file. – user2455242 Jun 05 '13 at 13:04
2 Answers
0
You can get running threads like this:
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
Then output the information you need of each thread. Once donecreate a batch file which calls your java file using: java ProgrammName
CloudyMarble
- 36,156
- 70
- 93
- 127
0
The top rated answer to this question: kill -3 to get java thread dump suggests using jstack. Run this on the command line using the pid (from task manager) and redirect the output to a file. Then read it with your batch file.
For example:
jstack -l 5980 > threaddump.txt
Community
- 1
- 1
Dave Richardson
- 4,661
- 5
- 26
- 46