zoukankan      html  css  js  c++  java
  • 提供者模式:提供者的实例化加锁

    private static DataProvider _provider = null;

     private static readonly object SyncLock = new object();

    private static void LoadProviders()
    {
        // providers are loaded just once
        if (null == _providers)
        {
            // Synchronize the process of loading the providers
            lock (SyncLock)
            {
                // Double confirm that the _provider is still null.
                if (null == _provider)
                {
                    try
                    {
                        // Reads the webconfig file corresponding node.
                        DataProviderSection section = (DataProviderSection)
                                                      WebConfigurationManager.GetSection("system.web/dataProviderService");
    
                        _providers = new DataProviderCollection();
    
                        // Creates provider instance, and invokes ProviderBase's Initialize function.
                        ProvidersHelper.InstantiateProviders(section.Providers, Providers, typeof(DataProvider));
    
                        // Gets the default in the collection.
                        _provider = Providers[section.DefaultProvider];
                    }
                    catch
                    {
                        throw new ProviderException("Can't create instance");
                    }
                }
            }
        }
    }
  • 相关阅读:
    OpenStack概述、虚拟机部署OpenStack
    foo bar 的典故
    PWA
    react 虚拟dom心得
    背包问题总结
    leetcode 44 通配符匹配(dp)
    黑客与画家
    njuoj 递归查询字符串
    我的第一篇博客
    接口测试入门(二)
  • 原文地址:https://www.cnblogs.com/Med1tator/p/6959302.html
Copyright © 2011-2022 走看看