ITeye博客

corleonelu

corleonelu · 共 4 篇文章

java并发实战读书笔记-3章

3.1 可见性 sychronized关键字的作用有两个:1是原子性 2是可见性。后者常常被忽视 NoVisibility程序演示没有同步的的共享变量。 3.1.1 失效数据 3.1.2 非原子的64位操作:存在于非volatile或没有加锁控制的long和double 3.1.3 加锁的与可见性 3.1.4 volatile 数据为共享,不会被缓存在寄存器和其他对对于处理器不可见的地方,每个线程不会有数据的本地拷贝。 volatile的用法: http://www.ibm.com/developerworks/cn/java/j-jtp06197.html 3.2 发布与逃逸 什么是发布 …

2012-04-25 14:22 · java · 评论(0)

java concurrent学习-简单的synchronized vs lock vs atomic

package concurrentstudy; import java.io.IOException; import java.util.*; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import ja…

2012-04-10 12:15 · java · 评论(0)

java string的hashcode

public int hashCode() { int h = hash; if (h == 0) { int off = offset; char val[] = value; int len = count; for (int i = 0; i < len; i++) { h = 31*h + val[off++]; } hash = h; } return h; } 实际上是使用霍纳法则计算 即 s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] 的值 选择31是因为他为素数,且他等于左移5位-1的值,vm会自动做这种优化 http://book.…

2011-09-20 16:11 · java · algorithm · 评论(0)

一致性哈希

http://article.yeeyan.org/view/119809/124126 http://ptsolmyr.com/2010/07/30/consistent_hash_by_tom_white/ 我最近一段时间在研究 consistent hash。介绍它的paper( Consistent Hashing and Random Trees: Distributed Caching Protocols for Relieving Hot Spots on the World Wide Web by David Karger et al) 十年前就出现了,不过直到最近才悄悄的有…

2011-08-14 09:15 · algorithm · 评论(0)