ConcurrentHashMap与HashTable
ConcurrentHashMap
通过CAS锁实现,使用了synchonized(node)搜索链表,只有输入操作有锁,输出操作无锁HashTable
通过synchronized方法实现,也就是用this作为锁,粒度过大
ConcurrentHashMap在开源项目的使用
- Mybatis中执行动态SQL时缓存表达式(expressionCache)
CopyOnWriteHashMap在开源项目的使用
- zk中的zkNode节点
- tomcat中的ApplicationContext,即request.getServletContext().getAttribute("key")