Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

According to the Java Language Specification [JLS 2011], §8.3.1.4, "volatile Fields" [JLS 2011],"

A field may be declared volatile, in which case the Java Memory Model ensures that all threads see a consistent value for the variable (§17.4).

...

This noncompliant code example attempts to use the volatile-read, synchronized-write technique described by Goetz in Java Theory and Practice [Goetz 2007]. The map field is declared volatile to synchronize its reads and writes. The put() method is also synchronized to ensure that its statements are executed atomically.

...

Because DateFormat is not thread-safe [API 2011], the value for Date returned by the parse() method might fail to correspond to the str argument.:

Compliant Solution (Instance per Call/Defensive Copying)

...

[API 2011]

Class DateFormat

[Goetz 2007]

Pattern 2, "One-Time Safe Publication"

[JLS 2011]

§8.3.1.4, "volatile Fields"

[Miller 2009]

"Mutable Statics"

...