![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
多线程
文章平均质量分 64
黑夜沉默客
这个作者很懒,什么都没留下…
展开
-
Synchronized
1.工具 JOL = java object Layout(去maven 仓库找) <groupId>org.openjdk.jol</groupId> <artifactId>jol-core</artifactId> <version>0.9</version> 二.当new 一个对象 会在JVM 中发生什么? 一个方法对应一个栈帧 Object 0 = new Object(); o会放在栈中 ,然后new Object 在原创 2021-04-21 23:35:46 · 306 阅读 · 0 评论 -
并发编程之原子性
CAS 名词解释:compare and swap 功能原理: 在java 中的应用 1.AtomicInteger i = new AtomicInteger() 不用加锁,也能在多线程中对值进行更新! i.incrementAndGet(); public final int incrementAndGet() { return unsafe.getAndAddInt(this, valueOffset, 1) + 1; } ``public final int getAnd原创 2021-04-21 22:50:21 · 202 阅读 · 0 评论 -
volatile 保证线程之间可见性 和 缓存
1.保证线程之间可见性 线程:线程执行的基本单位 进程:CPU 分配资源的基本单位 超线程:一个ALU 对应多个PC | Registers 寄存器,所谓四核八线程 flag 在内存中,一个线程对他进行访问,把这个值是赋值给他自己的本地内存,在主线程中把flag 值设置成false,但是其他线程见不到~! cache line 缓存行 对齐 伪共享 CPU 到内存之中有很多缓存 ,L1,L2,L3,主存。数据是按块读,内存块(cache line )!!一行数据64字节!! MESI :CPU 之前的数原创 2021-05-05 19:15:15 · 168 阅读 · 0 评论 -
多线程之interrupt
interrupt 三兄弟 interrupt 设置中断标志位,打不打断,看线程自己安排 [当程序处于sleep,wait,join状态时打断线程,会抛出InterruptedException并重置标志位] isInterrupted 查询某线程是否被打断过 (查询标志位) interrupted 查询当前线程是否被打断过,重置标志位 案例证明:(同时interrupt 也能优雅的结束线程) public class InterruptIsWho { public static void main(Str原创 2021-11-28 16:20:10 · 442 阅读 · 0 评论