JMH: Rework samples to avoid excess double and volatile cases

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P4
    • None
    • Affects Version/s: None
    • Component/s: tools
    • None
    • jmh

      This isn't really a bug as the code in question is just an example for benchmarking purposes, but it's a bit surprising to see the following code in the JMH tutorials:

      volatile double x = Math.PI;
      ...
      x++;

      Isn't incrementing a volatile field like that always a bug in real code, due to lack of atomicity? I wonder if someone reads this and thinks it's something Java lets you do.

            Assignee:
            Aleksey Shipilev
            Reporter:
            Mike Hearn
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: