packagetest;publicclassTestBank{publicstaticvoidmain(String[]args){newTestBank().run();}publicvoidrun(){Familyf=newFamily();newThread(f).start();while(true){System.out.pr...
package test;
public class TestBank {
public static void main(String[] args) {
new TestBank().run();
}
public void run(){
Family f=new Family();
new Thread(f).start();
while(true){
System.out.print("");//就是这一句,删了后程序没有显示东西并且一直运行,没删的话正常输出123,然后程序结束;如果将下面的sleep语句删了也是正常的,这两个地方是为什么?
if(f.times>0){
f.show();
break;
}
}
}
class Family implements Runnable{
private int times = 0;
@Override
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
times++;
}
public void show(){
System.out.println("123");
}
}
}
展开