/** * Atomically gets the current initialized value. If the current value is {@code null} * then the supplied initializer is called to create the value returned. * @param initializer the initializer to call if the current value is {@code null} * @return the initialized value. May return {@code null} if initializer returns null. */ public final V getInitialized(Callable<V> initializer) { V result = holder.get(); if (result != null) { return result; } // Must hold a lock to ensure the operation is atomic. synchronized (holder) { result = holder.get(); if (result != null) { return result; } try { result = initializer.call(); } catch (Exception e) { unchecked(e); } holder.set(result); return result; } }
/** * Atomically gets the current initialized value. If the current value is {@code null} * then the supplied initializer is called to create the value returned. * @param initializer the initializer to call if the current value is {@code null} * @return the initialized value. May return {@code null} if initializer returns null. */ public final V getInitialized(Callable<V> initializer) { V result = holder.get(); if (result != null) { return result; } // Must hold a lock to ensure the operation is atomic. synchronized (holder) { result = holder.get(); if (result != null) { return result; } try { result = initializer.call(); } catch (Exception e) { unchecked(e); } holder.set(result); return result; } }
/** * Atomically gets the current initialized value. If the current value is {@code null} * then the supplied initializer is called to create the value returned. * @param initializer the initializer to call if the current value is {@code null} * @return the initialized value. May return {@code null} if initializer returns null. */ public final V getInitialized(Callable<V> initializer) { V result = holder.get(); if (result != null) { return result; } // Must hold a lock to ensure the operation is atomic. synchronized (holder) { result = holder.get(); if (result != null) { return result; } try { result = initializer.call(); } catch (Exception e) { unchecked(e); } holder.set(result); return result; } }
/** * Atomically gets the current initialized value. If the current value is {@code null} * then the supplied initializer is called to create the value returned. * @param initializer the initializer to call if the current value is {@code null} * @return the initialized value. May return {@code null} if initializer returns null. */ public final V getInitialized(Callable<V> initializer) { V result = holder.get(); if (result != null) { return result; } // Must hold a lock to ensure the operation is atomic. synchronized (holder) { result = holder.get(); if (result != null) { return result; } try { result = initializer.call(); } catch (Exception e) { unchecked(e); } holder.set(result); return result; } }
/** * Atomically gets the current initialized value. If the current value is {@code null} * then the supplied initializer is called to create the value returned. * @param initializer the initializer to call if the current value is {@code null} * @return the initialized value. May return {@code null} if initializer returns null. */ public final V getInitialized(Callable<V> initializer) { V result = holder.get(); if (result != null) { return result; } // Must hold a lock to ensure the operation is atomic. synchronized (holder) { result = holder.get(); if (result != null) { return result; } try { result = initializer.call(); } catch (Exception e) { unchecked(e); } holder.set(result); return result; } }