java静态方法线程安全_Java线程类静态映射getAllStackTraces()方法(带示例)

java静态方法线程安全

线程类静态映射getAllStackTraces() (Thread Class static Map getAllStackTraces())

  • This method is available in package java.lang.Thread.getAllStackTraces().

    软件包java.lang.Thread.getAllStackTraces()中提供了此方法。

  • This method is used to return a Map of stack traces for all the existing or live threads.

    此方法用于返回所有现有或活动线程的堆栈跟踪图。

  • This method returns a Map and Map include two factors one is key and other is value. So key represents thread and value is an array of elements of StackTrace that denotes the stack dump of the corresponding thread.

    此方法返回一个Map,并且Map包含两个因素,一个是键,另一个是值。 所以key表示线程,value是StackTrace元素的数组,表示相应线程的堆栈转储。

  • This method is static so this method is accessible with classname too like Thread.getAllStackTraces().

    此方法是静态的,因此也可以使用类名访问该方法,例如Thread.getAllStackTraces() 。

  • The return type of this method is Map so it returns an array of stack trace elements of the desired or corresponding thread.

    此方法的返回类型为Map,因此它返回所需或相应线程的堆栈跟踪元素数组。

  • This method raises an exception if check access permission denies getting a stack trace of the thread.

    如果检查访问权限拒绝获取线程的堆栈跟踪,则此方法将引发异常。

Syntax:

句法:

    static Map getAllStackTraces(){
    }

Parameter(s):

参数:

We don't pass any object as a parameter in the method of the Thread.

我们不会在Thread方法中将任何对象作为参数传递。

Return value:

返回值:

The return type of this method is Map which contains thread and array of stack trace elements of the corresponding thread.

此方法的返回类型是Map ,其中包含线程和相应线程的堆栈跟踪元素数组。

Java程序演示getAllStackTraces()方法的示例 (Java program to demonstrate example of getAllStackTraces() method)

/*  We will use Thread class methods so we are importing 
    the package but it is not mandate because 
    it is imported by default
*/
import java.lang.Thread;
import java.util.Map;

class GetAllStackTraces extends Thread {
    // We are overriding run() method of Thread class 
    // in  GetAllStackTraces
    public void run() {
        System.out.println("We are in GetAllStackTraces run() method");
    }

    public static void main(String[] args) {
        // Creating a thread object of GetAllStackTraces
        GetAllStackTraces gast = new GetAllStackTraces();

        // Creating a Thread class object and pass 
        // GetAllStackTraces gast object into it .
        Thread th = new Thread(gast);

        /*  Call start() method of thread class and 
            then thread class start() will call run() 
            of GetAllStackTraces
        */
        th.start();

        // Return a map of stack traces of the corresponding thread
        Map m = Thread.getAllStackTraces();
    }
}

Output

输出量

E:\Programs>javac GetAllStackTraces.java

E:\Programs>java GetAllStackTraces
We are in GetAllStackTraces run() method


翻译自: https://www.includehelp.com/java/thread-class-static-map-getallstacktraces-method-with-example.aspx

java静态方法线程安全

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值