一直认为main为守护线程,google线程相关的资料时,发现有人说main函数是实时线程,特举例证明此结论!
public static void main(String[] args) throws InterruptedException {
Thread t = Thread.currentThread();
System.out.println("Thread name:"+t.getName());
System.out.println("Thread.isDaemon="+t.isDaemon());;
}
运行结果:
Thread name:main
Thread.isDaemon=false
本文通过实例分析,揭示Java中main函数并非守护线程,而是实时线程的特点,通过打印线程名与isDaemon属性,直观展示线程属性与运行时行为。
764

被折叠的 条评论
为什么被折叠?



