package com.company.bingfa;
import java.util.concurrent.LinkedBlockingQueue;
class MyThread16 extends Thread{
private LinkedBlockingQueue<String> list;
MyThread16(LinkedBlockingQueue<String> list){
this.list = list;
}
@Override
public void run() {
for (int i = 0; i < 100; i++) {
list.add("a");
}
}
}
public class MyLinkedBlockingQueue {
public static void main(String[] args) throws InterruptedException {
LinkedBlockingQueue<String> list = new LinkedBlockingQueue<>();
Thread[] threads = new Thread[100];
for (int i = 0; i < 100; i++) {
threads[i] = new MyThread16(list);
}
for (int i = 0; i < 100; i++) {
threads[i].start();
}
for (int i = 0; i < 100; i++) {
threads[i].join();
}
System.out.println(list.size());
// list.add("a");
// list.add("b");
// list.add("c");
// list.add("c");
// System.out.println(list.poll());
// System.out.println(list.poll());
// System.out.println(list.poll());
// System.out.println(list.poll());
}
}