zoukankan      html  css  js  c++  java
  • Kotlin Lazy延迟初始化

    一、by Lazy 延迟初始化是线程安全吗?

    Lazy是线程安全的,系统默认给Lazy属性添加了同步锁。也就是LazyThreadSafetyMode.SYNCHRONIZED,使之在同一时刻只能有一个线程对Lazy属性初始化操作。

    /**
     * Specifies how a [Lazy] instance synchronizes initialization among multiple threads.
     */
    public enum class LazyThreadSafetyMode {
    
        /**
         * Locks are used to ensure that only a single thread can initialize the [Lazy] instance.
         */
        SYNCHRONIZED,
    
        /**
         * Initializer function can be called several times on concurrent access to uninitialized [Lazy] instance value,
         * but only the first returned value will be used as the value of [Lazy] instance.
         */
        PUBLICATION,
    
        /**
         * No locks are used to synchronize an access to the [Lazy] instance value; if the instance is accessed from multiple threads, its behavior is undefined.
         *
         * This mode should not be used unless the [Lazy] instance is guaranteed never to be initialized from more than one thread.
         */
        NONE,
    }
  • 相关阅读:
    如何封装一个Ajax函数
    了解Ajax及Ajax如何发送请求
    jQuery的animate动画方法及动画排队问题解决
    jQuery的几种显示隐藏方法
    冲鸭!电瓶车
    Qt中使用HTTPS
    空非空
    河西走廊
    “财富自由”者之殇
    说鞋
  • 原文地址:https://www.cnblogs.com/naray/p/13542118.html
Copyright © 2011-2022 走看看