Skip to content

Commit 39b2a71

Browse files
authored
修复错别字
1 parent 623f410 commit 39b2a71

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

note/JDK/深入解析ThreadPoolExecutor底层原理.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0));
1111

1212

1313

14-
在不同操作系统下,Java 中的 Integer 变量都是32位,ThreadPoolExecutor 使用前3位(31~29)表示线程池状态,用后29位(28~0)表示活跃线程数。
14+
在不同操作系统下,Java 中的 Integer 变量都是32位,ThreadPoolExecutor 使用前3位(31 ~ 29)表示线程池状态,用后29位(28 ~ 0)表示活跃线程数。
1515

1616
## COUNT_BITS
1717
COUNT_BITS的作用:用来划分 ctl 这个 int 变量的高低位边界。
@@ -22,7 +22,7 @@ private static final int COUNT_BITS = Integer.SIZE - 3; // 29
2222

2323

2424

25-
int的最大位值是32位,32 - 3 = 29。通过这29来控制高3位存线程池状态**<font style="color:#DF2A3F;">(注意这里不是线程,是线程池)</font>**,低29位表示线程池中worker数量。通过位移来实现高效操作。
25+
int的最大位值是32位,32 - 3 = 29。通过这29来控制高3位存线程池状态(注意这里不是线程,是线程池),低29位表示线程池中worker数量。通过位移来实现高效操作。
2626

2727
## CAPACITY
2828
CAPACITY的作用:用来表示 workerCount 线程数量部分的最大容量,同时也作为低 29 位的**<font style="color:#DF2A3F;">掩码</font>**
@@ -40,11 +40,10 @@ private static final int CAPACITY = (1 << COUNT_BITS) - 1;
4040

4141
2)对左移结果 - 1
4242

43-
(1 << COUNT_BITS) - 1:就是00100000 00000000 00000000 00000000 - 1,对于二进制,如果高位减1,会借位到对应位置-1。举例如下:
43+
(1 << COUNT_BITS) - 1:就是00100000 00000000 00000000 00000000 - 1,对于二进制,如果高位减1,会借位到对应位置减1。举例如下:
4444

4545
+ 01000 - 1 = 01000 - 01111 = 00111
4646
+ 00100000 00000000 00000000 00000000 - 1 = 00100000 00000000 00000000 00000000 - 00111111 11111111 11111111 11111111 = 00011111 11111111 11111111 11111111
47-
+ 口诀:对于这种数:00100000 00000000 00000000 00000000,它是“某一位是 1,右边全是 0”。
4847

4948
### 【扩展】掩码
5049
掩码 Mask,就是一串二进制位,用来通过位运算“筛选”出你想要的部分。在ThreadPoolExecutor里:

0 commit comments

Comments
 (0)