class TicketRun implements Runnable {
private int tick = 100;
private static final Object lock = new Object();
@Override
public void run() {
while (true) {
synchronized (lock) {
if (tick > 0) {
System.out.println(Thread.currentThread().getName()
+ "sale:" + tick--);
}
}
}
}
}
public class TicketDemo {
public static void main(String[] args) {
TicketRun tr = new TicketRun();
new Thread(tr).start();
new Thread(tr).start();
new Thread(tr).start();
}
}