using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace HlianServer.DBDaoImpl
{
/// <summary>
/// 数据库单例工厂
/// </summary>
public sealed class DBFactory
{
private static HlianKDStore hlianKDStore;
/// <summary>
/// 程序运行时,创建一个静态只读的进程辅助对象
/// </summary>
private static readonly object _hliankdlock = new object();
/// <summary>
/// 构造方法私有,外键不能通过New类实例化此类
/// </summary>
private DBFactory()
{
}
/// <summary>
/// 此方法是实例的访问点
/// </summary>
/// <returns></returns>
public static HlianKDStore getHlianKDStore()
{
//先判断实例是否存在,不存在再加锁处理
if (hlianKDStore == null)
{
//在同一时刻加了锁的那部分程序只有一个线程可以进入,
lock (_hliankdlock)
{
//如实例不存在,则New一个新实例,否则返回已有实例
if (hlianKDStore == null)
{
hlianKDStore = new HlianKDStore();
}
}
}
return hlianKDStore;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace HlianServer.DBDaoImpl
{
/// <summary>
/// 数据库单例工厂
/// </summary>
public sealed class DBFactory
{
private static HlianKDStore hlianKDStore;
/// <summary>
/// 程序运行时,创建一个静态只读的进程辅助对象
/// </summary>
private static readonly object _hliankdlock = new object();
/// <summary>
/// 构造方法私有,外键不能通过New类实例化此类
/// </summary>
private DBFactory()
{
}
/// <summary>
/// 此方法是实例的访问点
/// </summary>
/// <returns></returns>
public static HlianKDStore getHlianKDStore()
{
//先判断实例是否存在,不存在再加锁处理
if (hlianKDStore == null)
{
//在同一时刻加了锁的那部分程序只有一个线程可以进入,
lock (_hliankdlock)
{
//如实例不存在,则New一个新实例,否则返回已有实例
if (hlianKDStore == null)
{
hlianKDStore = new HlianKDStore();
}
}
}
return hlianKDStore;
}
}
}