【发布时间】:2019-08-28 18:04:51
【问题描述】:
在 Java 中,程序员可以更改主线程的名称。那么如何判断一个线程是不是主线程呢?
package bj.thread;
public class ThreadApp2 {
public static void main(String[] args) {
System.out.printf("The main thread name is %s\n", Thread.currentThread().getName());
Thread.currentThread().setName("not-main");
System.out.printf("The main thread name is %s\n", Thread.currentThread().getName());
}
}
输出:
The main thread name is main
The main thread name is not-main
【问题讨论】:
-
一个线程是否是主线程对你来说很重要?
-
Java 中的主线程没有什么特别之处,只是它是调用应用程序的
main方法的线程。应用程序可以在主线程停止运行很长时间后继续运行。
标签: java multithreading