• Java内存Happen-Before


    • 在Thread.start之前的操作,hb 线程里面的操作
    • 对一个锁的解锁,hb 重新获得锁
    • 一个线程里的所有操作,hb其他线程调用这个线程的join返回后。
    • 对一个volatile的写入操作,hb读取操作
    • 对一个并发集合(CopyOnWriteList等)的写入操作,hb于对他的删除、读取操作

      hb的含义,是之前的操作写入的东西,对之后的操作都是可见的

      具有传递性,如果A hb B,B hb C,那么A hb C

    • Each action in a thread happens-before every action in that thread that comes later in the program's order.
    • 在同一个线程里面,前面的操作总是 hb 后面的操作
    • An unlock (synchronized block or method exit) of a monitor happens-before every subsequent lock (synchronized block or method entry) of that same monitor. And because the happens-before relation is transitive, all actions of a thread prior to unlocking happen-before all actions subsequent to any thread locking that monitor.
    • 对于同一个锁,释放锁之前的操作,总是 hb 之后获取锁的操作。因此,之前获取锁的线程,总是hb之后获取锁的线程。
    • A write to a volatile field happens-before every subsequent read of that same field. Writes and reads of volatile fields have similar memory consistency effects as entering and exiting monitors, but do not entail mutual exclusion locking.
    • 对Volatile的写操作,总是hb读操作。对volatile的读写在进入和退出锁上有相似的的内存一致性,但不是互斥锁。
    • A call to start on a thread happens-before any action in the started thread.
    • 在Thread.start之前发生的,总是hb 线程里面执行的
    • All actions in a thread happen-before any other thread successfully returns from a join on that thread.
    • 在线程里面发生的,总是hb 线程Join返回之后发生的

    The methods of all classes in java.util.concurrent and its subpackages extend these guarantees to higher-level synchronization. In particular:

    • Actions in a thread prior to placing an object into any concurrent collection happen-before actions subsequent to the access or removal of that element from the collection in another thread.
    • 在同步集合中之前放入对象总是hb之后的读取和删除
    • Actions in a thread prior to the submission of a Runnable to an Executor happen-before its execution begins. Similarly for Callables submitted to an ExecutorService.
    • 在Executor执行之前发生的,总是hb提交的Runnable的代码
    • Actions taken by the asynchronous computation represented by a Future happen-before actions subsequent to the retrieval of the result via Future.get() in another thread.
    • 在Future里面执行的,总是hb Future.get之后发生的
    • Actions prior to "releasing" synchronizer methods such as Lock.unlockSemaphore.release, and CountDownLatch.countDown happen-before actions subsequent to a successful "acquiring" method such as Lock.lockSemaphore.acquireCondition.await, and CountDownLatch.await on the same synchronizer object in another thread.
    • 在锁释放前发生的(如Lock.unlockSemaphore.release, and CountDownLatch.countDown)总是hb 之后成功获取锁后发生的。
    • For each pair of threads that successfully exchange objects via an Exchanger, actions prior to the exchange() in each thread happen-before those subsequent to the corresponding exchange() in another thread.
    • 在两个通过Exchanger进行交换的线程,在调用exchange之前发生的,总是hb另外一个线程响应exchange
    • Actions prior to calling CyclicBarrier.await and Phaser.awaitAdvance (as well as its variants) happen-before actions performed by the barrier action, and actions performed by the barrier action happen-before actions subsequent to a successful return from the corresponding await in other threads.
    • 在调用CyclicBarrier.await and Phaser.awaitAdvance之前发生的,总是hb 被内存栅栏执行的动作,内存栅栏执行的动作,总是hb 其他线程调用await返回之后
  • 相关阅读:
    MySQL 列子查询及 IN、ANY、SOME 和 ALL 操作符的使用
    MySQL 标量子查询
    MySQL 子查询(subquery)语法与用法实例
    如何上传本地音乐获取MP3外链(欢迎分享和转载)
    RabbitMQ与Kafka的区别及其简单原理实现
    MySQL中varchar和char的区别
    MySQL降低insert, update, delete的优先级来优化性能
    Eclipse代码自动提示
    Java生成XML文件
    Java读取XML文件
  • 原文地址:https://www.cnblogs.com/bobdeng/p/8960783.html
Copyright © 2020-2023  润新知