...
Immutable members can be safely published by declaring them volatile as described in CON00-J. Declare shared variables as volatile to ensure visibility and prevent reordering of accessesKnow when to use volatile.
| Code Block | ||
|---|---|---|
| ||
class Foo {
private volatile Helper helper;
public synchronized Helper getHelper() {
return helper;
}
public synchronized void initialize(int num) {
helper = new Helper(num);
}
}
|
...