62,614
社区成员
发帖
与我相关
我的任务
分享
public class Star {
/**
* @param args
*/
public static void main(String[] args) {
Thread1 thread1 = new Thread1();
thread1.start();
for(int i=0;i<100000000;i++){//这里只是浪费点时间..然后把下面设置成false
}
thread1.ok=false;
}
}
class Thread1 extends Thread{
boolean ok =true;
@Override
public void run() {
while(ok){//通过ok变量控制循环.
System.out.println("ok");
}
System.out.println("while done");
}
}
...//此处省略n个ok.
ok
ok
ok
while done