ITeye博客

jnullpointer

jnullpointer · 共 8 篇文章

Architecture and Distributed Systems

这是一篇分布式可扩展架构设计的基础文章,看了以后觉得很受用,分享给各位看一下。附件是原文,原文链接:http://aosabook.org/en/distsys.html Open source software has become a fundamental building block for some of the biggest websites. And as those websites have grown, best practices and guiding principles around their architectures have emerged. This …

2015-04-29 12:08 · 评论(0)

ReferenceQueue的分析

之前看过hongjiang对ReferenceQueue的分析 http://hongjiang.info/java-referencequeue/ ,很赞的分析水准。仔细看完后,总是感觉有几个点还不是非常透彻,现在揣测着补充一下。 一.Reference类的pending成员 pending是由jvm来赋值的,当Reference内部的referent对象的可达状态改变时,jvm会将Reference对象放入pending链表。 实现的逻辑在referenceProcessor.cpp的enqueue_discovered_reflist方法 void ReferenceProcessor…

2014-11-06 17:18 · 评论(0)

Selector的wakeup的分析

Selector的wakeup的分析可以看http://www.iteye.com/topic/1113639 很久之前看过这篇文章,最近重新看,又有新的理解了。 selectNow的选择过程是非阻塞的,select(timeout)和select()的选择过程是阻塞的。 sun.nio.ch.PollSelectorImpl类中 protected int doSelect(long timeout) throws IOException { if (channelArray == null) throw new ClosedSelectorException(); processDere…

2014-10-13 22:46 · 评论(0)

NIO包的AbstractInterruptibleChannel分析

这两天重新看了一下java.nio.channels.spi.AbstractInterruptibleChannel的代码,感觉又有一些收获,记录一下。AbstractInterruptibleChannel实现了InterruptibleChannel接口。InterruptibleChannel接口的描述非常重要,直接影响AbstractInterruptibleChannel的行为: A channel that implements this interface is asynchronously closeable: If a thread is blocked in an I/…

2014-09-24 13:50 · 评论(0)

sun.misc.Unsafe的几个点

一.获取Unsafe,通用的办法利用反射机制 Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); unsafeField.setAccessible(true); Unsafe unsafe = (Unsafe) unsafeField.get(null); 二.Unsafe自己对调用者的检查 public static Unsafe getUnsafe() { Class cc = sun.reflect.Reflection.getCallerClass(2); if (cc.getClassLoader() !…

2014-09-13 23:14 · 评论(0)

Netty中PlatformDependent绕开受检查异常处理

Netty是个值得花时间学习的框架,即使一个不起眼的程序,都有值得深入学习的地方。比如:io.netty.util.internal.PlatformDependent类中,对异常的处理就非常巧妙。 经常会碰到这种情况,实现一个接口,接口签名是没有申明异常的。但在实现中却需要捕获异常。比如:guava包中的通用接口 public interface Supplier<T> { /** * Retrieves an instance of the appropriate type. * The returned object may or * may not be a new instance…

2014-09-10 14:07 · 评论(0)

DirectByteBuffer的几个点

1.代码中的'<<'写法 private long ix(int i) { return address + (i << 0); } 这个就等价下面这种写法,但为什么用(i << 0) private long ix(int i) { return address + i; } 我琢磨了很久,以为有什么特殊的考虑因素,后来看了其他openJDK6以后的代码才恍然大悟。DirectByteBuffer类是由Direct-X-Buffer.java作为模板生成的。生成的像其他的DirectShortBuffer和DirectCharBuffer是有 << 1。 待续...

2014-09-10 14:00 · 评论(0)

AbstractQueuedSynchronizer方法解析

private Node enq(final Node node) { for (;;) { Node t = tail; if (t == null) { // Must initialize if (compareAndSetHead(new Node())) tail = head; } else { node.prev = t; //如果设置t.next = node; //compareAndSetTail如果设置tail失败,则需要解除t的next关联,所以在compareAndSetTail设置成功后再设置t.next = node if (compareAndSetTail(…

2013-05-14 10:48 · 评论(0)