From c916112dd72e0263614fcc073b54c3f81b7ce8a2 Mon Sep 17 00:00:00 2001 From: yitter Date: Sat, 9 Jul 2022 20:21:55 +0800 Subject: [PATCH] =?UTF-8?q?go=E5=AE=9E=E7=8E=B0=EF=BC=8C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=8B=E4=B8=80=E6=97=B6=E9=97=B4=E6=88=B3=E5=89=8D=EF=BC=8C?= =?UTF-8?q?=E6=9A=82=E5=81=9C1ms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Go/source/idgen/SnowWorkerM1.go | 1 + Go/source/idgen/YitIdHelper.go | 23 +++++++++++++++-------- Go/source/regworkerid/reghelper.go | 5 +++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Go/source/idgen/SnowWorkerM1.go b/Go/source/idgen/SnowWorkerM1.go index cf28b62..e5b5e94 100644 --- a/Go/source/idgen/SnowWorkerM1.go +++ b/Go/source/idgen/SnowWorkerM1.go @@ -232,6 +232,7 @@ func (m1 *SnowWorkerM1) GetCurrentTimeTick() int64 { func (m1 *SnowWorkerM1) GetNextTimeTick() int64 { tempTimeTicker := m1.GetCurrentTimeTick() for tempTimeTicker <= m1._LastTimeTick { + time.Sleep(time.Duration(1) * time.Millisecond) tempTimeTicker = m1.GetCurrentTimeTick() } return tempTimeTicker diff --git a/Go/source/idgen/YitIdHelper.go b/Go/source/idgen/YitIdHelper.go index 6226f60..9142f1b 100644 --- a/Go/source/idgen/YitIdHelper.go +++ b/Go/source/idgen/YitIdHelper.go @@ -1,3 +1,10 @@ +/* + * 版权属于:yitter(yitter@126.com) + * 代码编辑:guoyahao + * 代码修订:yitter + * 开源地址:https://github.com/yitter/idgenerator + */ + package idgen import ( @@ -17,14 +24,14 @@ func SetIdGenerator(options *IdGeneratorOptions) { // NextId . func NextId() int64 { - if idGenerator == nil { - singletonMutex.Lock() - defer singletonMutex.Unlock() - if idGenerator == nil { - options := NewIdGeneratorOptions(1) - idGenerator = NewDefaultIdGenerator(options) - } - } + //if idGenerator == nil { + // singletonMutex.Lock() + // defer singletonMutex.Unlock() + // if idGenerator == nil { + // options := NewIdGeneratorOptions(1) + // idGenerator = NewDefaultIdGenerator(options) + // } + //} return idGenerator.NewLong() } diff --git a/Go/source/regworkerid/reghelper.go b/Go/source/regworkerid/reghelper.go index b974719..b3325ab 100644 --- a/Go/source/regworkerid/reghelper.go +++ b/Go/source/regworkerid/reghelper.go @@ -1,3 +1,8 @@ +/* + * 鐗堟潈灞炰簬锛歽itter(yitter@126.com) + * 寮婧愬湴鍧锛歨ttps://github.com/yitter/idgenerator + */ + package regworkerid import (