class TicketWindow extends Thread
{
private static int tickets = 100;
@Override
public void run() {
while (true)
{
if (tickets > 0)
{
Thread thread = Thread.currentThread();
String threadName = thread.getName();
System.out.println(threadName + "1: " + tickets--);
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
public class G {
public static void main(String[] args) {
new TicketWindow().start();
new TicketWindow().start();
new TicketWindow().start();
new TicketWindow().start();
}
}
运行结果: