1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

Merge pull request #2218 from hunao0221/patch-2

fix a possible issue in threadlocal.md
This commit is contained in:
Guide 2023-12-12 12:59:32 +08:00 committed by GitHub
commit cb4ede0507
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -692,7 +692,7 @@ private void resize() {
我们以`get(ThreadLocal1)`为例,通过`hash`计算后,正确的`slot`位置应该是 4`index=4`的槽位已经有了数据,且`key`值不等于`ThreadLocal1`,所以需要继续往后迭代查找。 我们以`get(ThreadLocal1)`为例,通过`hash`计算后,正确的`slot`位置应该是 4`index=4`的槽位已经有了数据,且`key`值不等于`ThreadLocal1`,所以需要继续往后迭代查找。
迭代到`index=5`的数据时,此时`Entry.key=null`,触发一次探测式数据回收操作,执行`expungeStaleEntry()`方法,执行完后,`index 5,8`的数据都会被回收,而`index 6,7`的数据都会前移。`index 6,7`前移之后,继续从 `index=5` 往后迭代,于是就在 `index=5` 找到了`key`值相等的`Entry`数据,如下图所示: 迭代到`index=5`的数据时,此时`Entry.key=null`,触发一次探测式数据回收操作,执行`expungeStaleEntry()`方法,执行完后,`index 5,8`的数据都会被回收,而`index 6,7`的数据都会前移。`index 6,7`前移之后,继续从 `index=5` 往后迭代,于是就在 `index=6` 找到了`key`值相等的`Entry`数据,如下图所示:
![](./images/thread-local/28.png) ![](./images/thread-local/28.png)