package com.company.bingfa;
import java.util.concurrent.ArrayBlockingQueue;
class MyThread15 extends Thread{
private ArrayBlockingQueue<String> list;
MyThread15(ArrayBlockingQueue<String> list){
this.list = list;
}
@Override
public void run() {
for (int i = 0; i < 100; i++) {
list.add("a");
}
}
}
public class MyArrayBlockingQueue {
public static void main(String[] args) throws InterruptedException {
ArrayBlockingQueue<String> list = new ArrayBlockingQueue<>(20000);
Thread[] threads = new Thread[100];
for (int i = 0; i < 100; i++) {
threads[i] = new MyThread15(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());
// ArrayBlockingQueue<String> list = new ArrayBlockingQueue<>(5);
// list.add("a");
// list.add("b");
// list.add("c");
// list.add("d");
// list.add("d");
// System.out.println(list.poll());
// System.out.println(list.poll());
// System.out.println(list.poll());
// System.out.println(list.poll());
// System.out.println(list.poll());
// System.out.println(list.size());
}
}