Skip to content

java.util 包详细设计文档

一、模块概述

包路径: com.linsir.abc.core.base.util

包含子包:

  • collection - 集合框架
    • list - List 实现
    • set - Set 实现
    • map - Map 实现
    • queue - Queue 实现
  • stream - Stream API
  • concurrent - 并发包
    • collection - 并发集合
    • executor - 线程池
    • lock - 锁机制

类数: 27个


二、集合框架 - List

包路径: com.linsir.abc.core.base.util.collection.list

类名功能描述核心方法
ArrayListImplementation简化版 ArrayList 实现add(), get(), remove(), grow()
LinkedListImplementation简化版 LinkedList 实现addFirst(), addLast(), remove()
ListPerformanceComparisonList 性能对比compareAddPerformance(), compareGetPerformance()

设计要点:

  • ArrayList 的动态扩容机制(1.5倍)
  • LinkedList 的双向链表结构
  • RandomAccess 接口的作用

三、集合框架 - Map

包路径: com.linsir.abc.core.base.util.collection.map

类名功能描述核心方法
HashMapImplementation简化版 HashMap 实现put(), get(), resize(), treeifyBin()
TreeMapImplementation简化版 TreeMap 实现put(), get(), rotateLeft(), rotateRight()
LinkedHashMapImplementation简化版 LinkedHashMap 实现afterNodeInsertion(), afterNodeRemoval()

设计要点:

  • HashMap 的哈希冲突解决(链表 + 红黑树)
  • 负载因子和扩容阈值
  • JDK 8 的链表转红黑树优化

四、集合框架 - Set

包路径: com.linsir.abc.core.base.util.collection.set

类名功能描述核心方法
HashSetImplementation基于 HashMap 实现 Setadd(), remove(), contains()
TreeSetImplementation基于 TreeMap 实现 Setadd(), first(), last()

设计要点:

  • Set 的去重原理(依赖 Map 的 key)
  • HashSet 和 TreeSet 的区别

五、集合框架 - Queue

包路径: com.linsir.abc.core.base.util.collection.queue

类名功能描述核心方法
PriorityQueueImplementation堆实现的优先队列offer(), poll(), siftUp(), siftDown()
ArrayDequeImplementation数组双端队列addFirst(), addLast(), pollFirst(), pollLast()

设计要点:

  • 二叉堆的实现(完全二叉树)
  • 优先队列的排序机制
  • 双端队列的循环数组实现

六、Stream API

包路径: com.linsir.abc.core.base.util.stream

类名功能描述核心方法
StreamPipelineBuilder流式操作链构建filter(), map(), sorted(), collect()
ParallelStreamProcessor并行流处理parallel(), sequential()
CustomCollector自定义收集器supplier(), accumulator(), combiner(), finisher()

设计要点:

  • 中间操作和终止操作的区别
  • 惰性求值机制
  • 并行流的线程安全问题

七、并发集合

包路径: com.linsir.abc.core.base.util.concurrent.collection

类名功能描述核心方法
ConcurrentHashMapImplementation简化版 ConcurrentHashMapput(), get(), transfer()
CopyOnWriteArrayListImplementation写时复制 Listadd(), get(), iterator()

设计要点:

  • 分段锁 vs CAS + synchronized
  • volatile 保证可见性
  • 写时复制的读写分离思想

八、线程池

包路径: com.linsir.abc.core.base.util.concurrent.executor

类名功能描述核心方法
ThreadPoolExecutorImplementation简化版线程池execute(), addWorker(), runWorker()
ScheduledExecutorImplementation定时任务执行器schedule(), scheduleAtFixedRate()
TaskRejectHandler任务拒绝策略rejectedExecution()

设计要点:

  • 核心线程数和最大线程数
  • 任务队列的作用
  • 拒绝策略的实现

九、锁机制

包路径: com.linsir.abc.core.base.util.concurrent.lock

类名功能描述核心方法
ReentrantLockImplementation简化版可重入锁lock(), unlock(), tryLock()
ReadWriteLockImplementation读写锁实现readLock(), writeLock()
ConditionVariable条件变量await(), signal(), signalAll()

设计要点:

  • AQS(AbstractQueuedSynchronizer)框架
  • 独占锁和共享锁的区别
  • 条件变量的等待/通知机制

十、完整类名列表

序号完整类名
1com.linsir.abc.core.base.util.collection.list.ArrayListImplementation
2com.linsir.abc.core.base.util.collection.list.LinkedListImplementation
3com.linsir.abc.core.base.util.collection.list.ListPerformanceComparison
4com.linsir.abc.core.base.util.collection.map.HashMapImplementation
5com.linsir.abc.core.base.util.collection.map.TreeMapImplementation
6com.linsir.abc.core.base.util.collection.map.LinkedHashMapImplementation
7com.linsir.abc.core.base.util.collection.set.HashSetImplementation
8com.linsir.abc.core.base.util.collection.set.TreeSetImplementation
9com.linsir.abc.core.base.util.collection.queue.PriorityQueueImplementation
10com.linsir.abc.core.base.util.collection.queue.ArrayDequeImplementation
11com.linsir.abc.core.base.util.stream.StreamPipelineBuilder
12com.linsir.abc.core.base.util.stream.ParallelStreamProcessor
13com.linsir.abc.core.base.util.stream.CustomCollector
14com.linsir.abc.core.base.util.concurrent.collection.ConcurrentHashMapImplementation
15com.linsir.abc.core.base.util.concurrent.collection.CopyOnWriteArrayListImplementation
16com.linsir.abc.core.base.util.concurrent.executor.ThreadPoolExecutorImplementation
17com.linsir.abc.core.base.util.concurrent.executor.ScheduledExecutorImplementation
18com.linsir.abc.core.base.util.concurrent.executor.TaskRejectHandler
19com.linsir.abc.core.base.util.concurrent.lock.ReentrantLockImplementation
20com.linsir.abc.core.base.util.concurrent.lock.ReadWriteLockImplementation
21com.linsir.abc.core.base.util.concurrent.lock.ConditionVariable

文档版本: 1.0.0
最后更新: 2026-03-26

Released under the MIT License.