Class BestEffortLazyVal<T>

Object
org.apache.spark.util.BestEffortLazyVal<T>
All Implemented Interfaces:
Serializable

public class BestEffortLazyVal<T> extends Object implements Serializable
A lock-free implementation of a lazily-initialized variable. If there are concurrent initializations then the `compute()` function may be invoked multiple times. However, only a single `compute()` result will be stored and all readers will receive the same result object instance. This may be helpful for avoiding deadlocks in certain scenarios where exactly-once value computation is not a hard requirement.
See Also:
Note:
This helper class has additional requirements on the compute function: 1) The compute function MUST not return null; 2) The computation failure is not cached., Scala 3 uses a different implementation of lazy vals which doesn't have this problem. Please refer to Lazy Vals Initialization for more details.
  • Constructor Details

    • BestEffortLazyVal

      public BestEffortLazyVal(scala.Function0<T> compute)
  • Method Details

    • apply

      public T apply()