public class Demo01 {
public static void main(String[] args) {
new Tickets().start();
new Tickets().start();
new Tickets().start();
new Tickets().start();
}
}
class Tickets extends Thread {
private static int tickets = 100;
public void run() {
synchronized(Tickets.class) {
while(true) {
if(tickets <= 0) {
break;
}else {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(getName() + "---第" + tickets-- + "张票");
}
}
}
}
}
lvshen9 发表于 2017-3-19 20:11
都在循环外了,感觉没有用到
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |