数组的可见性,与 数组元素 的可见性,是否是一回事?
比如private volatile int[] data;
这里的volatile,是保证data字段的可见性,那对于data里的元素,比如data[18],是否也有volatile的语义呢?
看如下代码
package learn.concurrency.jcip; import java.util.concurrent.TimeUnit; public class VolatileArrayTest { private volatile int[] data; public VolatileArrayTest() { this.data = new int[20]; } public void check() { while (this.getArray()[18] == 0) { } System.out.println("no equal, over"); } public void change() { this.getArray()[18] = 1; int[] sameData = this.getArray(); // comment this in scenario 2 this.setArray(sameData);// comment this in scenario 2 } private int[] getArray() { return this.data; } private void setArray(int[] data) { this.data = data; } public static void main(String[] args) throws InterruptedException { final VolatileArrayTest test = new VolatileArrayTest(); new Thread(new Runnable() { @Override public void run() { test.check(); } }).start(); TimeUnit.SECONDS.sleep(5); new Thread(new Runnable() { @Override public void run() { test.change(); } }).start(); } }
架上神器HSDIS,查看check和change的汇编。
这里的汇编,关键的行,我都增加了注释
Decoding compiled method 0x00007fec29129bd0:
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'check' '()V' in 'learn/concurrency/jcip/VolatileArrayTest'
# [sp+0x30] (sp of caller)
0x00007fec29129d20: mov 0x8(%rsi),%r10d
0x00007fec29129d24: cmp %r10,%rax
0x00007fec29129d27: jne 0x00007fec29037620 ; {runtime_call}
0x00007fec29129d2d: xchg %ax,%ax
[Verified Entry Point]
0x00007fec29129d30: mov %eax,-0x14000(%rsp)
0x00007fec29129d37: push %rbp
0x00007fec29129d38: sub $0x20,%rsp ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::check@-1 (line 14)
0x00007fec29129d3c: rex mov 0xc(%rsi),%ebp ;*getfield data // 获取VolatileArrayTest实例的data字段,其实地址为12=0xc
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::check@1 (line 14)
0x00007fec29129d40: mov 0xc(%rbp),%r10d ; implicit exception: dispatches to 0x00007fec29129dc9
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'check' '()V' in 'learn/concurrency/jcip/VolatileArrayTest'
# [sp+0x30] (sp of caller)
0x00007fec29129d20: mov 0x8(%rsi),%r10d
0x00007fec29129d24: cmp %r10,%rax
0x00007fec29129d27: jne 0x00007fec29037620 ; {runtime_call}
0x00007fec29129d2d: xchg %ax,%ax
[Verified Entry Point]
0x00007fec29129d30: mov %eax,-0x14000(%rsp)
0x00007fec29129d37: push %rbp
0x00007fec29129d38: sub $0x20,%rsp ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::check@-1 (line 14)
0x00007fec29129d3c: rex mov 0xc(%rsi),%ebp ;*getfield data // 获取VolatileArrayTest实例的data字段,其实地址为12=0xc
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::check@1 (line 14)
0x00007fec29129d40: mov 0xc(%rbp),%r10d ; implicit exception: dispatches to 0x00007fec29129dc9
//获取数组的长度
0x00007fec29129d44: cmp $0x12,%r10d // 比较 索引18 与 数组长度,这就是java能够发现index越界的地方
0x00007fec29129d48: jbe 0x00007fec29129da5 ;*iaload // 非法,则跳转到0x00007fec29129da5
; - learn.concurrency.jcip.VolatileArrayTest::check@6 (line 14)
0x00007fec29129d4a: mov 0x58(%rbp),%r10d //获取数组的地址为0x58=88的值,数组的内存布局头为8+4+4,第18个元素就是4*18
0x00007fec29129d4e: test %r10d,%r10d //测试data[18]是否为0
0x00007fec29129d51: jne 0x00007fec29129d7d //如果data[18] !=0,则跳转到0x00007fec29129d7d
0x00007fec29129d53: nopw 0x0(%rax,%rax,1) //后续的指令不管了,是循环代码的重复
0x00007fec29129d5c: xchg %ax,%ax ;*getstatic out
; - learn.concurrency.jcip.VolatileArrayTest::check@10 (line 18)
0x00007fec29129d60: mov 0xc(%rsi),%r10d ;*getfield data
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::check@1 (line 14)
0x00007fec29129d64: mov 0xc(%r10),%r8d ; implicit exception: dispatches to 0x00007fec29129db9
0x00007fec29129d68: cmp $0x12,%r8d
0x00007fec29129d6c: jbe 0x00007fec29129d8d
0x00007fec29129d6e: mov 0x58(%r10),%r11d ; OopMap{rsi=Oop off=82}
;*ifeq
; - learn.concurrency.jcip.VolatileArrayTest::check@7 (line 14)
0x00007fec29129d72: test %eax,0x99f3288(%rip) # 0x00007fec32b1d000
; {poll}
0x00007fec29129d78: test %r11d,%r11d
0x00007fec29129d7b: je 0x00007fec29129d60 ;*getstatic out
; - learn.concurrency.jcip.VolatileArrayTest::check@10 (line 18)
0x00007fec29129d7d: mov $0x18,%esi
0x00007fec29129d82: nop
0x00007fec29129d44: cmp $0x12,%r10d // 比较 索引18 与 数组长度,这就是java能够发现index越界的地方
0x00007fec29129d48: jbe 0x00007fec29129da5 ;*iaload // 非法,则跳转到0x00007fec29129da5
; - learn.concurrency.jcip.VolatileArrayTest::check@6 (line 14)
0x00007fec29129d4a: mov 0x58(%rbp),%r10d //获取数组的地址为0x58=88的值,数组的内存布局头为8+4+4,第18个元素就是4*18
0x00007fec29129d4e: test %r10d,%r10d //测试data[18]是否为0
0x00007fec29129d51: jne 0x00007fec29129d7d //如果data[18] !=0,则跳转到0x00007fec29129d7d
0x00007fec29129d53: nopw 0x0(%rax,%rax,1) //后续的指令不管了,是循环代码的重复
0x00007fec29129d5c: xchg %ax,%ax ;*getstatic out
; - learn.concurrency.jcip.VolatileArrayTest::check@10 (line 18)
0x00007fec29129d60: mov 0xc(%rsi),%r10d ;*getfield data
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::check@1 (line 14)
0x00007fec29129d64: mov 0xc(%r10),%r8d ; implicit exception: dispatches to 0x00007fec29129db9
0x00007fec29129d68: cmp $0x12,%r8d
0x00007fec29129d6c: jbe 0x00007fec29129d8d
0x00007fec29129d6e: mov 0x58(%r10),%r11d ; OopMap{rsi=Oop off=82}
;*ifeq
; - learn.concurrency.jcip.VolatileArrayTest::check@7 (line 14)
0x00007fec29129d72: test %eax,0x99f3288(%rip) # 0x00007fec32b1d000
; {poll}
0x00007fec29129d78: test %r11d,%r11d
0x00007fec29129d7b: je 0x00007fec29129d60 ;*getstatic out
; - learn.concurrency.jcip.VolatileArrayTest::check@10 (line 18)
0x00007fec29129d7d: mov $0x18,%esi
0x00007fec29129d82: nop
Decoding compiled method 0x00007fec290e5b10:
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'change' '()V' in 'learn/concurrency/jcip/VolatileArrayTest'
# [sp+0x30] (sp of caller)
0x00007fec290e5c60: mov 0x8(%rsi),%r10d
0x00007fec290e5c64: cmp %r10,%rax
0x00007fec290e5c67: jne 0x00007fec29037620 ; {runtime_call}
0x00007fec290e5c6d: xchg %ax,%ax
[Verified Entry Point]
0x00007fec290e5c70: mov %eax,-0x14000(%rsp)
0x00007fec290e5c77: push %rbp
0x00007fec290e5c78: sub $0x20,%rsp ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::change@-1 (line 22)
0x00007fec290e5c7c: mov 0xc(%rsi),%r11d ;*getfield data //获取data字段
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::change@1 (line 22)
0x00007fec290e5c80: mov 0xc(%r11),%r10d ; implicit exception: dispatches to 0x00007fec290e5cd9 //获取data的length字段
0x00007fec290e5c84: cmp $0x12,%r10d //比较下标18和length
0x00007fec290e5c88: jbe 0x00007fec290e5cc0 //小标非法,则跳转到0x00007fec290e5cc0
0x00007fec290e5c8a: movl $0x1,0x58(%r11) ;*synchronization entry // data[18]设置为1
; - learn.concurrency.jcip.VolatileArrayTest::getArray@-1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::change@9 (line 24)
0x00007fec290e5c92: mov 0xc(%rsi),%r10d // 获取data字段,存入%r10d
0x00007fec290e5c96: mov %r10d,0xc(%rsi) // %10d写入data字段
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'change' '()V' in 'learn/concurrency/jcip/VolatileArrayTest'
# [sp+0x30] (sp of caller)
0x00007fec290e5c60: mov 0x8(%rsi),%r10d
0x00007fec290e5c64: cmp %r10,%rax
0x00007fec290e5c67: jne 0x00007fec29037620 ; {runtime_call}
0x00007fec290e5c6d: xchg %ax,%ax
[Verified Entry Point]
0x00007fec290e5c70: mov %eax,-0x14000(%rsp)
0x00007fec290e5c77: push %rbp
0x00007fec290e5c78: sub $0x20,%rsp ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::change@-1 (line 22)
0x00007fec290e5c7c: mov 0xc(%rsi),%r11d ;*getfield data //获取data字段
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::change@1 (line 22)
0x00007fec290e5c80: mov 0xc(%r11),%r10d ; implicit exception: dispatches to 0x00007fec290e5cd9 //获取data的length字段
0x00007fec290e5c84: cmp $0x12,%r10d //比较下标18和length
0x00007fec290e5c88: jbe 0x00007fec290e5cc0 //小标非法,则跳转到0x00007fec290e5cc0
0x00007fec290e5c8a: movl $0x1,0x58(%r11) ;*synchronization entry // data[18]设置为1
; - learn.concurrency.jcip.VolatileArrayTest::getArray@-1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::change@9 (line 24)
0x00007fec290e5c92: mov 0xc(%rsi),%r10d // 获取data字段,存入%r10d
0x00007fec290e5c96: mov %r10d,0xc(%rsi) // %10d写入data字段
0x00007fec290e5c9a: lock addl $0x0,(%rsp) // 内存屏障,用来刷新
0x00007fec290e5c9f: mov %rsi,%r10
0x00007fec290e5ca2: shr $0x9,%r10
0x00007fec290e5ca6: mov $0x7fec2fb69000,%r11
0x00007fec290e5cb0: mov %r12b,(%r11,%r10,1) ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::change@-1 (line 22)
0x00007fec290e5cb4: add $0x20,%rsp
0x00007fec290e5cb8: pop %rbp
0x00007fec290e5c9f: mov %rsi,%r10
0x00007fec290e5ca2: shr $0x9,%r10
0x00007fec290e5ca6: mov $0x7fec2fb69000,%r11
0x00007fec290e5cb0: mov %r12b,(%r11,%r10,1) ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::change@-1 (line 22)
0x00007fec290e5cb4: add $0x20,%rsp
0x00007fec290e5cb8: pop %rbp
红色部分,发现了lock指令, 对应的代码是:this.setArray(sameData)
而我们在check方法中,会读取data值,这就完成了data字段的volatile读和写,也就完成了HB
我们注释掉2行代码,继续执行:
Decoding compiled method 0x00007fb74d12b890:
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'check' '()V' in 'learn/concurrency/jcip/VolatileArrayTest'
# [sp+0x30] (sp of caller)
0x00007fb74d12b9e0: mov 0x8(%rsi),%r10d
0x00007fb74d12b9e4: cmp %r10,%rax
0x00007fb74d12b9e7: jne 0x00007fb74d037620 ; {runtime_call}
0x00007fb74d12b9ed: xchg %ax,%ax
[Verified Entry Point]
0x00007fb74d12b9f0: mov %eax,-0x14000(%rsp)
0x00007fb74d12b9f7: push %rbp
0x00007fb74d12b9f8: sub $0x20,%rsp ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::check@-1 (line 14)
0x00007fb74d12b9fc: rex mov 0xc(%rsi),%ebp ;*getfield data
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::check@1 (line 14)
0x00007fb74d12ba00: mov 0xc(%rbp),%r10d ; implicit exception: dispatches to 0x00007fb74d12ba89
0x00007fb74d12ba04: cmp $0x12,%r10d
0x00007fb74d12ba08: jbe 0x00007fb74d12ba65 ;*iaload
; - learn.concurrency.jcip.VolatileArrayTest::check@6 (line 14)
0x00007fb74d12ba0a: mov 0x58(%rbp),%r10d
0x00007fb74d12ba0e: test %r10d,%r10d
0x00007fb74d12ba11: jne 0x00007fb74d12ba3d
0x00007fb74d12ba13: nopw 0x0(%rax,%rax,1)
0x00007fb74d12ba1c: xchg %ax,%ax ;*getstatic out
; - learn.concurrency.jcip.VolatileArrayTest::check@10 (line 18)
0x00007fb74d12ba20: mov 0xc(%rsi),%r10d ;*getfield data
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::check@1 (line 14)
0x00007fb74d12ba24: mov 0xc(%r10),%r8d ; implicit exception: dispatches to 0x00007fb74d12ba79
0x00007fb74d12ba28: cmp $0x12,%r8d
0x00007fb74d12ba2c: jbe 0x00007fb74d12ba4d
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'check' '()V' in 'learn/concurrency/jcip/VolatileArrayTest'
# [sp+0x30] (sp of caller)
0x00007fb74d12b9e0: mov 0x8(%rsi),%r10d
0x00007fb74d12b9e4: cmp %r10,%rax
0x00007fb74d12b9e7: jne 0x00007fb74d037620 ; {runtime_call}
0x00007fb74d12b9ed: xchg %ax,%ax
[Verified Entry Point]
0x00007fb74d12b9f0: mov %eax,-0x14000(%rsp)
0x00007fb74d12b9f7: push %rbp
0x00007fb74d12b9f8: sub $0x20,%rsp ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::check@-1 (line 14)
0x00007fb74d12b9fc: rex mov 0xc(%rsi),%ebp ;*getfield data
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::check@1 (line 14)
0x00007fb74d12ba00: mov 0xc(%rbp),%r10d ; implicit exception: dispatches to 0x00007fb74d12ba89
0x00007fb74d12ba04: cmp $0x12,%r10d
0x00007fb74d12ba08: jbe 0x00007fb74d12ba65 ;*iaload
; - learn.concurrency.jcip.VolatileArrayTest::check@6 (line 14)
0x00007fb74d12ba0a: mov 0x58(%rbp),%r10d
0x00007fb74d12ba0e: test %r10d,%r10d
0x00007fb74d12ba11: jne 0x00007fb74d12ba3d
0x00007fb74d12ba13: nopw 0x0(%rax,%rax,1)
0x00007fb74d12ba1c: xchg %ax,%ax ;*getstatic out
; - learn.concurrency.jcip.VolatileArrayTest::check@10 (line 18)
0x00007fb74d12ba20: mov 0xc(%rsi),%r10d ;*getfield data
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::check@1 (line 14)
0x00007fb74d12ba24: mov 0xc(%r10),%r8d ; implicit exception: dispatches to 0x00007fb74d12ba79
0x00007fb74d12ba28: cmp $0x12,%r8d
0x00007fb74d12ba2c: jbe 0x00007fb74d12ba4d
Decoding compiled method 0x00007fb74d0d41d0:
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'change' '()V' in 'learn/concurrency/jcip/VolatileArrayTest'
# [sp+0x20] (sp of caller)
0x00007fb74d0d4320: mov 0x8(%rsi),%r10d
0x00007fb74d0d4324: cmp %r10,%rax
0x00007fb74d0d4327: jne 0x00007fb74d037620 ; {runtime_call}
0x00007fb74d0d432d: xchg %ax,%ax
[Verified Entry Point]
0x00007fb74d0d4330: mov %eax,-0x14000(%rsp)
0x00007fb74d0d4337: push %rbp
0x00007fb74d0d4338: sub $0x10,%rsp ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::change@-1 (line 22)
0x00007fb74d0d433c: mov 0xc(%rsi),%r11d ;*getfield data
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::change@1 (line 22)
0x00007fb74d0d4340: mov 0xc(%r11),%r10d ; implicit exception: dispatches to 0x00007fb74d0d4371
0x00007fb74d0d4344: cmp $0x12,%r10d
0x00007fb74d0d4348: jbe 0x00007fb74d0d435e
0x00007fb74d0d434a: movl $0x1,0x58(%r11) ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::change@-1 (line 22)
0x00007fb74d0d4352: add $0x10,%rsp
0x00007fb74d0d4356: pop %rbp
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} 'change' '()V' in 'learn/concurrency/jcip/VolatileArrayTest'
# [sp+0x20] (sp of caller)
0x00007fb74d0d4320: mov 0x8(%rsi),%r10d
0x00007fb74d0d4324: cmp %r10,%rax
0x00007fb74d0d4327: jne 0x00007fb74d037620 ; {runtime_call}
0x00007fb74d0d432d: xchg %ax,%ax
[Verified Entry Point]
0x00007fb74d0d4330: mov %eax,-0x14000(%rsp)
0x00007fb74d0d4337: push %rbp
0x00007fb74d0d4338: sub $0x10,%rsp ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::change@-1 (line 22)
0x00007fb74d0d433c: mov 0xc(%rsi),%r11d ;*getfield data
; - learn.concurrency.jcip.VolatileArrayTest::getArray@1 (line 30)
; - learn.concurrency.jcip.VolatileArrayTest::change@1 (line 22)
0x00007fb74d0d4340: mov 0xc(%r11),%r10d ; implicit exception: dispatches to 0x00007fb74d0d4371
0x00007fb74d0d4344: cmp $0x12,%r10d
0x00007fb74d0d4348: jbe 0x00007fb74d0d435e
0x00007fb74d0d434a: movl $0x1,0x58(%r11) ;*synchronization entry
; - learn.concurrency.jcip.VolatileArrayTest::change@-1 (line 22)
0x00007fb74d0d4352: add $0x10,%rsp
0x00007fb74d0d4356: pop %rbp
这2段汇编,与第1种类似,唯一的区别在于: change方法中,没有lock指令了,也就没有了内存屏障,所以这就不满足HB原则, 对于 可见性来说是无法保障的。
尽管2个场景的代码,在执行上,目前都是正确的,都能结束循环。
相关推荐
这本书的读书笔记涵盖了多个关键知识点,旨在帮助读者深入理解Java并发编程的核心概念。 1. **线程和进程的区别** - **线程** 是程序执行的最小单位,一个进程中可以有多个线程同时执行,共享同一块内存空间,通信...
这本"Java并发编程学习笔记"可能是作者在深入研究Java并发特性、工具和最佳实践过程中积累的心得体会。下面,我们将根据这个主题,探讨一些关键的Java并发编程知识点。 1. **线程与进程**:在多任务环境中,线程是...
Java并发编程系列心得笔记,可以参考,欢迎共同交流学习
### Java并发编程实践笔记知识点详解 #### 一、保证线程安全的方法 1. **不要跨线程访问共享变量:** 当多个线程共享某个变量时,若其中一个线程修改了该变量,其他线程若没有正确同步,则可能读取到错误的数据。...
java并发编程的艺术读书笔记根据章节整理的核心内容,便于自己理解
Java并发编程是Java开发中必不可少的一部分,涉及到多线程、同步机制、线程池以及并发工具类等多个核心知识点。以下是对这些主题的详细说明: 1. **线程安全与锁 Synchronized 底层实现原理**: 线程安全是指在多...
读书笔记:Java并发编程之美笔记
### Java并发编程知识点详解 #### 一、线程状态与管理 在Java中,线程具有多种状态,这些状态的变化反映了线程在其生命周期中的不同阶段。理解这些状态及其转换对于编写高效、健壮的并发程序至关重要。 - **NEW**...
《Java并发编程的艺术》笔记 第一章 并发编程的挑战 第二章 Java并发机制的底层实现原理 volatile的两条实现原则: 1. Lock前缀指令会引起处理器缓存回写到内存 2. 一个处理器的缓存回写到内存会导致其他...
在Java并发编程中,数据的封装与访问控制、线程安全性的考量、同步机制的使用是重要的基础概念和技巧。以下是从给出的文件内容中提取出的详细知识点: 1. 数据封装与访问控制:确保内部私有数据不被轻易访问,并且...
《Java并发编程实战》个人读书笔记,非常详细: 1 简介 2 线程安全性 3 对象的共享 4 对象的组合 5 基础构建模块 6 任务执行 7 取消与关闭 8 线程池的使用 9 图形用户界面应用程序 10 避免活跃性危险 11 性能与可...
Java并发编程实践笔记 Java并发编程实践笔记是一份关于Java并发编程的实践笔记,涵盖了多种关于线程安全、并发编程的实践经验和原则。下面是从笔记中总结的知识点: 1. 保证线程安全的三种方法:不要跨线程访问...
《java并发编程实战》读书笔记-第3章-对象的共享,脑图形式,使用xmind8制作 包括可见性、发布与逸出、线程封闭、不可变性、安全发布等内容
### Java并发编程笔记 #### 实现Runnable接口与继承Thread类 在Java中,实现多线程功能主要有两种途径:一种是通过实现`Runnable`接口,另一种则是通过继承`Thread`类。这两种方式各有优劣,具体选择哪一种取决于...
### Java并发编程学习笔记知识点详解 #### 一、Java并发编程概述 Java并发编程是指在Java应用程序中同时执行多个操作的技术。它通过多线程、线程池等机制实现资源的有效利用,提高程序运行效率。Java并发编程的...
本文将基于文档《Java并发编程与高并发解决方案-学习笔记***.pdf》中提供的内容,来详细阐述并发编程和高并发的基本概念、CPU多级缓存与缓存一致性、以及Java内存模型。 ### 并发与高并发概念 在现代多线程编程中...
读书笔记:Java并发编程之美读书笔记
《java并发编程实战》读书笔记-第3章-对象的共享,脑图形式,使用xmind8制作 包括线程安全类设计、实例封闭、线程安全性委托、现有线程安全类中添加功能和文档化同步策略等内容
《java并发编程实战》读书笔记-第2章-线程安全性,脑图形式,使用xmind8制作 包括引言、线程安全性定义、原子性、加锁机制、使用锁保护状态、活跃性与性能等内容