class MyThread implements Runnable {
private int ticket = 30;
public void run() {
for (int x = 0; x < 5; x++) {
if (this.ticket > 0) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("卖票,ticket =" + this.ticket--);
}
}
}
}
public class TestDemo2 {
public static void main(String[] args) {
MyThread mt = new MyThread();
new Thread(mt).start();
new Thread(mt).start();
new Thread(mt).start();
}
}