保持java线程间可见性的5种方式
2023-03-14 10:19:24 时间
Primitive | Writes up to and including… | ...are made visible to… |
---|---|---|
Object | the end of a synchronized block or method | a thread entering a synchronized block or method for the same object. |
Volatile field | a write to a volatile field | any thread reading that volatile field. |
Thread | a call to Thread.start |
the newly started thread. |
Thread | the final write made by a dying thread | any thread which successfully calls Thread.join on that thread. |
Final field | the initialization of a final field (but only those writes affecting the field and any object it references) | any thread, provided that the constructor of the object containing the field doesn’t write the value of this anywhere eventually visible to other threads |
这些在《java并发编程实践》一书中已经有详细解释,特别是对于ReentrantLock、volatile域以及final域的讨论。今天在MenTaLguY的blog上看到这张表,摘录下
文章转自庄周梦蝶 ,原文发布时间2008-02-23
相关文章
- PHP:6种GET和POST请求发送方法
- 为什么有些技术人员不写博客?
- 如何在 Java 中正确使用 wait, notify 和 notifyAll
- C#实现日历样式的下拉式计算器
- 去了大公司就一定能学到很牛的技术么?
- 驱动力来自哪里-献给迷茫的程序员
- Java删除ArrayList中的重复元素的2种方法
- 10个Java 8 Lambda表达式经典示例
- 深入分析Java线程中断机制
- Windows10的第一天使用总结
- 二十个热门的高级Java面试题汇总
- 秒杀Siri Win10的人工智能强在哪里
- Java9先睹为快:JShell动手实践
- 每个程序员和设计师必做的10项运动
- Java 8 中所有的包列表及介绍
- Java 中最常见的五个错误
- Java 自定义实现 LRU 缓存算法
- 一个性能较好的JVM参数配置
- 技术人员在大公司能学到什么
- Java开发者对甲骨文摒弃私有API的计划表示不满