collections + map
1. collections 包括 set list queue(为高并发 多线程准备put take)
安全 vector + hashtable 太重 自带锁 基本不用
hashtable(插入快 读慢) hashMap Collections.synchronizedMap concurrentHashMap(插入效率低 读效率高) 一路发展 。。升级
票超卖问题
vector
list
Collections.synchronizedList(strs)
concurrentLinkedQueue (poll 拿取) 多线程
---------------------------------------------------------------------------------------
concurrentHashMap concurrentSkipListMap(跳表 高并发排序) 因为在treeMap中 cas操作 过于复杂所以 concurrentSkipListMap 替代 concurrentTreeMap
--------------------------------------------------
(读多写少)copyOnWriteArrayList / copyOnWriteSet 读的时候不加锁 效率高 写的时候加锁 写时复制
----------------------------------------------------------
blockQueue 阻塞队列
concurrentLinkedQueue
Queue 方法 offer 返回值 poll 取 remove掉 peek 取 不会remove 线程安全 原子性
blockQueue 阻塞队列 方法 put take
本文探讨了Java并发编程中的集合框架,从Vector到ConcurrentHashMap的发展,提到了不同集合在并发环境下的性能特点。重点介绍了CopyOnWriteArrayList和ConcurrentSkipListMap在读多写少场景下的优势,以及BlockQueue在多线程间的协同操作。同时,还讨论了阻塞队列的方法如offer、poll和put、take的使用。
1157

被折叠的 条评论
为什么被折叠?



