code_junkie

Finding running instances in a running JVM

Nov 13th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. public Set<Thread> findThreadsRunningClass(Class classToFindRunning) {
  2.  
  3. Set<Thread> runningThreads = new HashSet<Thread>();
  4. String className = classToFindRunning.getName();
  5.  
  6. Map<Thread,StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
  7. for(Thread t : stackTraces.keySey()) {
  8. StackTraceElement[] steArray = stackTraces.get(t);
  9. for(int i = 0;i<steArray.size();i++) {
  10. StackTraceElement ste = steArray[i];
  11. if(ste.getClassName().equals(className)) {
  12. runningThreads.add(t);
  13. continue;
  14. }
  15. }
  16. }
  17.  
  18. return runningThreads;
  19. }
  20.  
  21. $ kill -QUIT <pid of java process>
Add Comment
Please, Sign In to add comment