一道Java面试题,求大佬讲解
public class Test { static Runnable runnable = new Runnable() { @Override public void run() { System.out.println(Thread.currentThread().getName()+":开始"); DeadThread deadThread = new DeadThread(); System.out.println(Thread.currentThread().getName()+":结束"); } }; public static void main(String[] args) { Thread t1 = new Thread(runnable); Thread t2 = new Thread(runnable); t1.start(); t2.start(); } } class DeadThread{ static { if(true) { System.out.println(Thread.currentThread().getName()+":lllllll"); while (true){ } } } }输出结果:
Thread-1:开始
Thread-0:开始
Thread-1:lllllll
或者
Thread-0:开始
Thread-1:开始
Thread-1:lllllll
等等
Thread-1:开始
Thread-1:lllllll
等等
为什么只有一个llllllll
#面试题目#