I would move this up one more line. The only time it needs to be set to true is
when we set "elderState". If we get inside this lock and find elderState is not
null then another thread initialized it.
Maybe it would make it more clear if you changed the if to be:
if (!elderStateInitialized) {
this.elderStateInitialized = true;
this.elderState = elderStateSupplier.get();
}
Another approach would be to get rid of the boolean elderStateInitialized and
just have "elderState". You would need to make "elderState" volatile. Any code
that wants to see if it is initialized would just test "elderState != null".
This might be the best solution since it gets rid of an instance variable and
you no longer need to think about how "elderState" and "elderStateInitialized"
are related to each other.
[ Full content available at: https://github.com/apache/geode/pull/2393 ]
This message was relayed via gitbox.apache.org for [email protected]