枚举类报错 getid报错_Java Thread类的long getId()方法(带示例)

枚举类报错 getid报错

线程类long getId() (Thread Class long getId())

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

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

  • This method is used to return an Id (Identifier) for this thread.

    此方法用于返回此线程的ID(标识符)。

  • This method is not static so this method is accessible with Thread class object it is not accessible with the class name.

    此方法不是静态的,因此该方法可通过Thread类对象访问,而无法通过类名称访问。

  • Every Thread has a unique id and creates id at the thread instantiation.

    每个线程都有一个唯一的ID,并在线程实例化时创建ID。

  • We cannot change Id of the Thread even when the thread terminates and Id may reuse again.

    即使线程终止,我们也无法更改线程的ID,并且ID可能会再次重用。

  • This method does not raise any exception.

    此方法不会引发任何异常。

Syntax:

句法:

    long getId(){
    }

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 long, it returns the Id for this thread and Id will be long integer type.

此方法的返回类型为long ,它返回此线程的ID,而Id将为long整数类型。

Java程序演示getId()方法的示例 (Java program to demonstrate example of getId() 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;

class GetThreadId extends Thread {
    // Override run() of Thread class
    public void run() {
        System.out.println("The priority of this thread is : " + Thread.currentThread().getPriority());
    }

    public static void main(String[] args) {
        // Creating an object of GetThreadId class
        GetThreadId gt_id = new GetThreadId();

        // Calling start() method with GetThreadId class 
        // object of Thread class
        gt_id.start();

        // Get name of a thread th and display on standard 
        // output stream
        System.out.println("The name of this thread is " + " " + gt_id.getName());

        // Get Id of a thread th and display on standard 
        // output stream
        System.out.println("The Id of this thread is " + " " + gt_id.getId());
    }
}

Output

输出量

E:\Programs>javac GetThreadId.java

E:\Programs>java GetThreadId
The priority of this thread is :5
The name of this thread is  Thread-0
The Id of this thread is  9


翻译自: https://www.includehelp.com/java/thread-class-long-getid-method-with-example.aspx

枚举类报错 getid报错

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值