Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-7903641

JMH: Rework samples to avoid excess double and volatile cases

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • None
    • None
    • 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.

            shade Aleksey Shipilev
            mhearn Mike Hearn
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: