...
Code Block | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
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.
...