为什么这里运行不出来,是我 new Thread(ticke,"小明").start();这一句出错了吗?该怎么修改?

img


为什么这里运行不出来,是我 new Thread(ticke,"小明").start();这一句出错了吗?该怎么修改?
package test;
//模拟购买火车票
class Ticke implements Runnable{
private int TickeNums=10;
public void run() {
while(true) {
if(TickeNums<=0) {
break;
}//模拟延时
try {
Thread.sleep(20000);
}catch(InterruptedException e){
System.out.println("出现异常");
}
}
System.out.println(Thread.currentThread().getName()+"--拿到了第"+TickeNums+"票");
}
}
public class test5 {

public static void main(String[] args) {
    Ticke ticke=new Ticke();
    new Thread(ticke,"小明").start();
    }

}

class Ticke implements Runnable{
private int TickeNums=10;
public void run() {
while(true) {
if(TickeNums<=0) {
TickeNums--
break;
}//模拟延时
try {
Thread.sleep(20000);
}catch(InterruptedException e){
System.out.println("出现异常");
}
}
System.out.println(Thread.currentThread().getName()+"--拿到了第"+TickeNums+"票");
}
}

public class test5 {
public static void main(String[] args) {
    Ticke ticke=new Ticke();
   tick.start();
    }
}

你的循环while (true)是个死循环吗,没有退出退出条件

你这买了票之后怎么票数没有变呢,需要加上TickeNums--