** * Nodes for use in TreeBins */
static final class TreeNode<K,V> extends
Node<K,V> { TreeNode<K,V> parent; //
red-black tree links TreeNode<K,V> left;
TreeNode<K,V> right; TreeNode<K,V> prev;
// needed to unlink next upon deletion
boolean red; ...... }
TreeBin 这个类并不负责包装用户的 key、value 信息,而是包装的很多
TreeNode 节点。实际的 ConcurrentHashMap“数组”中,存放的是 TreeBin
对象,而不是 TreeNode 对象。
static final class TreeBin<K,V> extends Node<K,V>
{ TreeNode<K,V> root;
volatile TreeNode<K,V> first;
volatile Thread waiter; volatile int
lockState; // values for lockState
static final int WRITER = 1; // set while holding write
lock static final int WAITER = 2; // set when
waiting for write lock static final int
READER = 4; // increment value for setting read lock
...... }
ForwardingNode 在扩容时才会出现的特殊节点,其 key,value,hash 全部
为 null。并拥有 nextTable 指针引用新的 table 数组。
static final class ForwardingNode<K,V> extends
Node<K,V> { final Node<K,V>[] nextTable;
ForwardingNode(Node<K,V>[] tab) {
评论0