Java 关于这篇文章的问题

Java 关于这篇文章的问题,java,multithreading,volatile,Java,Multithreading,Volatile,我看到: Pattern #2: one-time safe publication The visibility failures that are possible in the absence of synchronization can get even trickier to reason about when writing to object references instead of primitive values. In the absence of synchronizat

我看到:

Pattern #2: one-time safe publication
The visibility failures that
are possible in the absence of synchronization can get even trickier
to reason about when writing to object references instead of primitive
values. In the absence of synchronization, it is possible to see an
up-to-date value for an object reference that was written by another
thread and still see stale values for that object's state. (This
hazard is the root of the problem with the infamous
double-checked-locking idiom, where an object reference is read
without synchronization, and the risk is that you could see an
up-to-date reference but still observe a partially constructed object
through that reference.)*

我很困惑:

  • 什么是“原始值”
  • 原因:“查看由另一个线程编写的对象引用的最新值,但仍然可以看到该对象状态的过时值”
  • 1) 基本值不是像int、boolean、float等那样的对象。请记住,有一些对象与它们等价,例如Integer、boolean等

    2) 此线程可能会看到更新的对象引用,但该对象可能未完全初始化。e、 当这个线程获取对象的新的更新引用时,如果构造函数还没有完成,这可能会发生。。。这可能很复杂,但在某些JVM实现中可能会发生。

    1)基本值不是像int、boolean、float等那样的对象。请记住,它们有一些对象等价物,如Integer、boolean等


    2) 此线程可能会看到更新的对象引用,但该对象可能未完全初始化。e、 当这个线程获取对象的新的更新引用时,如果构造函数还没有完成,这可能会发生。。。这可能很复杂,但在某些JVM实现中可能会发生。

    我曾经问过一个类似于2的问题,并得到了一个很好的答案:我曾经问过一个类似于2的问题,并得到了一个很好的答案: