package com.example.demo;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedDeque;
public class TicketSeller {
static Queue<String> tickets = new ConcurrentLinkedDeque<>();
static {
for (int i = 0;i < 1000;i++)tickets.add("车票编号:"+i);
}
public static void main(String[] args) {
for (int i = 0;i <10;i++){
new Thread(()->{
for (;;){//等价于while(true)
String s = tickets.poll();
if(s == null)break;
else System.out.println("销售出->"+s);
}
}).start();
}
}
}