关于多线程出现异常
public class TestThread1 {
public static void main(String[] args) {
Thread2 t1 = new Thread2();
t1.setName("子线程");
Thread.currentThread().setName("主-----线程");
t1.start();
for (int j = 1; j <= 50; j++) {
System.out.println(Thread.currentThread().getName() + ":" + j);
}
}
}
class Thread2 extends Thread {
//出现Exception in thread "main" java.lang.StackOverflowError
//Thread2 t = new Thread2();// 加入此句为什么会出现异常。
public void run() {
for (int i = 0; i <= 50; i++) {
System.out.println(Thread.currentThread().getName() + ":" + i);
if (i == 30) {
yield();
System.out.println(isAlive());
}
}
}
}