package com.alibaba.study;
import java.util.Random;
public class Tickets implements Runnable{
int total = 100;
int count = 0;
@Override
public void run() {
while(total>0){
synchronized (this) {
if(total>0){
try {
Thread.sleep(new Random().nextInt(500));
total--;
count++;
System.out.println(Thread.currentThread().getName()+"当前票号"+count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
public static void main(String[] args) {
Tickets tickets = new Tickets();
for (int i = 0; i < 5; i++) {
new Thread(tickets,"代售点"+i).start();
}
}
}