You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
private T instance; // no need to declare it volatile
public T get() {
if (missing) {
synchronized (this) {
if (missing) {
instance = supplier.get();
missing = false; // publish only after a valid value is assigned to instance
}
}
}
return instance; // missing is volatile, so this read is going to happen
}
@olotenko could you please have a look at the PR?
I have added a slightly more complex fix - I have created a LazyValue interface that is used to wrap the concept of "get once and cache" and to be properly thread safe (without using the synchronized keyword.
I have also updated our ExecutorService suppliers to use the new component.
https://github.com/oracle/helidon/blob/1dacd76/common/context/src/main/java/io/helidon/common/context/ListContext.java#L190-L191 - the order of assignments allows to observe
instance
to be null.The correct order is:
Also, you probably do not need to hold on to
supplier
after the first use.ListContext.java.1dacd76.diff.zip - a diff against 1dacd76
The text was updated successfully, but these errors were encountered: