目录

static Map<Thread,StackTraceElement[]> getAllStackTraces()

描述 (Description)

java.lang.Thread.getAllStackTraces()方法返回所有活动线程的堆栈跟踪映射。 映射键是线程,每个映射值都是StackTraceElement数组,表示相应Thread的堆栈转储。

声明 (Declaration)

以下是java.lang.Thread.getAllStackTraces()方法的声明

public static Map<Thread,StackTraceElement[]> getAllStackTraces()

参数 (Parameters)

NA

返回值 (Return Value)

此方法将Map从Thread返回到StackTraceElement数组,该数组表示相应线程的堆栈跟踪。

异常 (Exception)

SecurityException - 如果存在安全管理器且其checkPermission方法不允许获取线程的堆栈跟踪。

例子 (Example)

以下示例显示了java.lang.Thread.getAllStackTraces()方法的用法。

package com.iowiki;
import java.lang.*;
import java.util.*;
public class ThreadDemo implements Runnable {
   public void run() {
      System.out.println("This is run() method");
   }
   public static void main(String args[]) {
      ThreadDemo trace = new ThreadDemo();
      Thread t = new Thread(trace);
      // this will call run() method
      t.start();
      // returns a map of stack traces
      Map m = Thread.getAllStackTraces();
   }
} 

让我们编译并运行上面的程序,这将产生以下结果 -

This is run() method
↑回到顶部↑
WIKI教程 @2018