package com.company.bingfa;
import java.util.concurrent.ConcurrentLinkedQueue;
class MyThread14 extends Thread{
private ConcurrentLinkedQueue<String> list;
MyThread14(ConcurrentLinkedQueue<String> list){
this.list = list;
}
@Override
public void run() {
for (int i = 0; i < 100; i++) {
list.add("a");
}
}
}
public class MyConcurrentLinkedQueue {
public static void main(String[] args) throws InterruptedException {
ConcurrentLinkedQueue<String> list = new ConcurrentLinkedQueue<>();
Thread[] threads = new Thread[100];
for (int i = 0; i < 100; i++) {
threads[i] = new MyThread14(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());
/*
10000
*/
}
}