java
7im0thyZhang
搬砖搬砖,空了再写
展开
-
Java String的hashcode()方法实现
闲来无事,看java源码。Talk is cheap, show me the code. public int hashCode() { int h = hash; if (h == 0 && value.length > 0) { char val[] = value; for (int i ...原创 2018-02-17 14:47:35 · 1588 阅读 · 1 评论 -
java多个线程同时启动的两种方式
【背景】今天遇到一个并发问题,为了在开发环境复现这个bug,需要让多个线程同时执行到某条语句。【解决方案】java1.5的concurrent包下的CyclicBarrier 和 CountDownLatch都能解决这个问题。不得不佩服Doug Lea!【方法1】使用CyclicBarrierpublic class TestCyclicBarrier { class Worke...原创 2019-01-23 21:54:55 · 25843 阅读 · 6 评论