JCTools是一款对jdk并发数据结构进行增强的并发工具,主要提供了map以及queue的增强数据结构。原来netty还是自己写的MpscLinkedQueueNode,后来新版本就换成使用JCTools的并发队列了。
后面几个map/set结构的基础
)<dependency> <groupId>org.jctools</groupId> <artifactId>jctools-core</artifactId> <version>2.1.0</version> </dependency>
替代AtomicLong,专门为高性能的counter设计的。只有几个方法
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主要是操作之后没有立即返回
public final long incrementAndGet(); public final long decrementAndGet()
原来是
// --- 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; }
本文分享自微信公众号 - 码匠的流水账(geek_luandun)
原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。
原始发表时间:2017-09-04
本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。
我来说两句