CopyOnWriteArrayList

CopyOnWriteArrayList

JUC 并发领域的概念 JUC:java.util.concurrent

package com.example.multi_thread;

import java.util.concurrent.CopyOnWriteArrayList;

public class TestJUC {
    public static void main(String[] args) throws InterruptedException {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
        for (int i = 0; i < 10000; i++) {
            new Thread(() -> list.add(Thread.currentThread().getName())).start();

        }

        Thread.sleep(1000);
        System.out.println(list.size());
    }
}

输出

10000
上一篇:24-10000 web开发入门-HTML布局 网页布局


下一篇:“21天好习惯” 第一期-15