package cn.itcast.iostream;
class ThreadTicket extends Thread {
private static int tickets = 100;
public void run() {
while (true) {
if (tickets > 0) {
System.out.println(getName() + "出售第" + tickets--);
}
}
}
}
public class ThreadDemo {
public static void main(String[] args) {
ThreadTicket tt0 = new ThreadTicket();
ThreadTicket tt1 = new ThreadTicket();
ThreadTicket tt2 = new ThreadTicket();
tt0.start();
tt1.start();
tt2.start();
}
}
|
|