//线程安全队列,先进先出 ConcurrentLinkedQueue conLinkedQueue = new ConcurrentLinkedQueue(); for(int i = 0;i<100;i++){ conLinkedQueue.add(i);//往队列加数据 }
//循环队列 while(!conLinkedQueue.isEmpty()){ //弹出数据 System.out.println("Thread Id :"+Thread.currentThread().getId()+" "+conLinkedQueue.poll()); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } }