Versions Compared

Key

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

...

Code Block
bgColor#FFcccc
public class Container<K,V> {
  Map<K,V> map;
  final int size = 1000;

  public Container() {
    map = new HashMap<K,V>();	
    // Put values in HashMap
  }

  public V get(Object k) {
    return map.get(k);
  }
}

...

Code Block
bgColor#ccccff
public class Container<K,V> {
  volatile Map<K,V> map;
  final int size = 1000;

  // ...
}

Risk Assessment

Failing to use volatile to guarantee visibility of shared values across multiple thread and prevent reordering of statements can result in unpredictable control flow.

...