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");
                    }
                }
            }
        }
    }
  • 相关阅读:
    python--Tuple类型
    python--List类型
    剑指offer--数组中重复的数字
    Assignment HDU
    kuangbin 并查集
    Girls and Boys-hdu 1068
    Computer HDU
    Terrorist’s destroy HDU
    Roads in the North POJ
    Labyrinth POJ
  • 原文地址:https://www.cnblogs.com/Med1tator/p/6959302.html
Copyright © 2011-2022 走看看