package com.heima.testhomework;
public class Demo3 {
public static void main(String[] args) {
ticket t = new ticket();
new Thread(t, "窗口a").start();
new Thread(t, "窗口b").start();
new Thread(t, "窗口c").start();
new Thread(t, "窗口d").start();
}
}
class ticket implements Runnable {
private int num = 100;
@Override
public void run() {
while (true) {
synchronized (this) {
if (num <= 0)
break;
try {
Thread.sleep(30);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + "第"
+ num-- + "张票");
}
}
}
} |
|