JCTools是一款对jdk并发数据结构进行加强的并发工具,主要提供了map以及queue的加强数据结构。原来netty仍是本身写的MpscLinkedQueueNode,后来新版本就换成使用JCTools的并发队列了。html
后面几个map/set结构的基础
)<dependency> <groupId>org.jctools</groupId> <artifactId>jctools-core</artifactId> <version>2.1.0</version> </dependency>
替代AtomicLong,专门为高性能的counter设计的。只有几个方法java
public void add( long x ); public void decrement(); public void increment(); public void set( long x ); public long get(); public int intValue(); public long longValue(); public long estimate_get();
对比AtomicLong主要是操做以后没有当即返回git
public final long incrementAndGet(); public final long decrementAndGet()
NonBlockingHashMap是对ConcurrentHashMap的加强,对多CPU的支持以及高并发更新提供更好的性能。
NonBlockingHashMapLong是key为Long型的NonBlockingHashMap。
NonBlockingHashSet是对NonBlockingHashMap的简单包装以支持set的接口。
NonBlockingIdentityHashMap是从NonBlockingHashMap改造来的,使用System.identityHashCode()来计算哈希
NonBlockingSetInt是一个使用CAS的简单的bit-vectorgithub
原来是数据结构
// --- hash ---------------------------------------------------------------- // Helper function to spread lousy hashCodes. Throws NPE for null Key, on // purpose - as the first place to conveniently toss the required NPE for a // null Key. private static final int hash(final Object key) { int h = key.hashCode(); // The real hashCode call h ^= (h>>>20) ^ (h>>>12); h ^= (h>>> 7) ^ (h>>> 4); h += h<<7; // smear low bits up high, for hashcodes that only differ by 1 return h; }
改成并发
// --- hash ---------------------------------------------------------------- // Helper function to spread lousy hashCodes private static final int hash(final Object key) { int h = System.identityHashCode(key); // The real hashCode call // I assume that System.identityHashCode is well implemented with a good // spreader, and a second bit-spreader is redundant. //h ^= (h>>>20) ^ (h>>>12); //h ^= (h>>> 7) ^ (h>>> 4); return h; }