public class yield {
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(new t3());
for(int i=1;i<=10;i++){
System.out.println("hi"+i);
if(i==5){
thread.start();//启动子线程
thread.join();//立即将t3子线程插入主线程优先子线程执行
}
}
}}
class t3 implements Runnable{
int count=0;
@Override
public void run() {
while (true){
System.out.println("hello"+(++count));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(count==10){
break;
}
}
}
}
java日常练习
最新推荐文章于 2024-07-15 22:27:12 发布