设计模式->单例模式

 public class RedisManagerSingleton
    {
        private static RedisManagerSingleton _redisManagerSingleton;

        private static readonly object _lock = new object();

        private RedisManagerSingleton()
        {
        }


        public static RedisManagerSingleton GetSingleton()
        {
            if (_redisManagerSingleton == null)
            {
                lock (_lock)
                {
                    if (_redisManagerSingleton == null)
                    {
                        _redisManagerSingleton = new RedisManagerSingleton();
                    }
                }
            }

            return _redisManagerSingleton;
        }
    }
posted @ 2022-01-13 00:53  icxl  阅读(20)  评论(0编辑  收藏  举报