关于wait方法
来源:7-3 notify方法

用户1148542
2020-07-22
public class WaitThread implements Runnable {
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(new WaitThread());
thread.start();
Thread.sleep(1);
thread.wait();
}
@Override
public void run() {
int num = 0;
while (num<999999){
num++;
System.out.println(“num=”+num);
}
}
}
我这么写 run方法还是会执行完毕的 我知道一般不会这么写,但不知道原理
写回答
1回答
-
悟空
2020-07-22
wait是针对执行线程的,在这里就是主线程,如果想让子线程wait,要在run方法里写
00
相似问题