Java如何获取当前正在执行的线程?
要获取当前正在执行的线程,请使用Thread类的静态currentThread()方法。此方法返回当前正在执行的线程对象的引用。
package org.nhooo.example.lang;
public class GetCurrentThreadDemo {
public static void main(String[] args){
// 获取当前正在执行的线程对象
Thread thread = Thread.currentThread();
System.out.println("Id : " + thread.getId());
System.out.println("Name : " + thread.getName());
System.out.println("Priority: " + thread.getPriority());
}
}该代码段显示以下输出:
Id : 1 Name : main Priority: 5
热门推荐
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特