mian方法进行测试,测试代码1
import java.util.ArrayList;
import cn.chinaunicom.thread.com.TestThread;
public class TestFor {
public static void main(String[] args) {
TestThread tt = new TestThread();
Thread thread1 = new Thread(tt,"测试线程一");
Thread thread2 = new Thread(tt,"测试线程二");
thread1.start();
thread2.start();
}
}
测试代码2
public class TestThread extends Thread{
@Override
public void run() {
for (int i = 0; i < 10; i++) {
if (i==3) {
try {
if(Thread.currentThread().getName()== "测试线程一"){
System.out.println(true);
}
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getName()+"出厂顺序"+i);
}
}
}
求解:运行代码1时候,测试代码2中加粗的代码没有执行的原因????