Thread.dumpStack() : Thread « java.lang « Java by API






Thread.dumpStack()

  
/*
 * Output:
 * 
current thread: Thread[My Thread,1,main]
currently active threads: 1
0: Thread[My Thread,1,main]
java.lang.Exception: Stack trace
  at java.lang.Thread.dumpStack(Thread.java:1158)
  at MainClass.main(MainClass.java:23)

 * 
 
 *  
 */

public class MainClass {
  public static void main(String args[]) {
    Thread t = Thread.currentThread();
    t.setName("My Thread");
    t.setPriority(1);
    System.out.println("current thread: " + t);
    int active = Thread.activeCount();
    System.out.println("currently active threads: " + active);
    Thread all[] = new Thread[active];
    Thread.enumerate(all);
    for (int i = 0; i < active; i++) {
      System.out.println(i + ": " + all[i]);
    }
    Thread.dumpStack();
  }
}


           
         
    
  








Related examples in the same category

1.Thread.MAX_PRIORITY
2.Thread.NORM_PRIORITY
3.new Thread(Runnable target, String name)
4.Thread.activeCount()
5.Thread.currentThread()
6.Thread.enumerate(Thread[] tarray)
7.Thread: getStackTrace()
8.Thread: getThreadGroup()
9.Thread: getUncaughtExceptionHandler()
10.Thread: interrupt()
11.Thread: isAlive()
12.Thread: isDaemon()
13.Thread: join() (Using join() to wait for threads to finish)
14.Thread: run()
15.Thread: setDaemon(boolean b)
16.Thread: setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler eh)
17.Threah.sleep(long millis)
18.Thread: setDaemon(boolean on)
19.Thread: setName(String name)
20.Thread: setPriority(int newPriority)
21.Thread: setUncaughtExceptionHandler(UncaughtExceptionHandler eh)
22.Thread: start
23.Thread: stop
24.implements UncaughtExceptionHandler