mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +08:00
Update SnowFlake id
This commit is contained in:
@@ -65,7 +65,10 @@ namespace SqlSugar.DistributedSystem.Snowflake
|
|||||||
// def get_timestamp() = System.currentTimeMillis
|
// def get_timestamp() = System.currentTimeMillis
|
||||||
|
|
||||||
readonly object _lock = new Object();
|
readonly object _lock = new Object();
|
||||||
|
public long getID()
|
||||||
|
{
|
||||||
|
return NextId();
|
||||||
|
}
|
||||||
public virtual long NextId()
|
public virtual long NextId()
|
||||||
{
|
{
|
||||||
lock(_lock)
|
lock(_lock)
|
||||||
|
|||||||
@@ -8,22 +8,38 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public sealed class SnowFlakeSingle
|
public sealed class SnowFlakeSingle
|
||||||
{
|
{
|
||||||
public static readonly SnowFlakeSingle instance = new SnowFlakeSingle();
|
private static object LockObject = new object();
|
||||||
|
private static DistributedSystem.Snowflake.IdWorker worker;
|
||||||
public static int WorkId = 1;
|
public static int WorkId = 1;
|
||||||
public static int DatacenterId = 1;
|
public static int DatacenterId = 1;
|
||||||
private SnowFlakeSingle()
|
private SnowFlakeSingle()
|
||||||
{
|
{
|
||||||
worker = new DistributedSystem.Snowflake.IdWorker(WorkId, DatacenterId);
|
|
||||||
}
|
}
|
||||||
static SnowFlakeSingle() { }
|
static SnowFlakeSingle() { }
|
||||||
public static SnowFlakeSingle Instance
|
public static DistributedSystem.Snowflake.IdWorker Instance
|
||||||
{
|
{
|
||||||
get { return instance; }
|
get
|
||||||
|
{
|
||||||
|
if (worker == null)
|
||||||
|
{
|
||||||
|
lock (LockObject)
|
||||||
|
{
|
||||||
|
if (worker == null)
|
||||||
|
{
|
||||||
|
worker = new DistributedSystem.Snowflake.IdWorker(WorkId, DatacenterId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return worker;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private DistributedSystem.Snowflake.IdWorker worker;
|
public static DistributedSystem.Snowflake.IdWorker instance
|
||||||
public long getID()
|
{
|
||||||
{
|
get
|
||||||
return worker.NextId();
|
{
|
||||||
|
return Instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user