1
0
mirror of synced 2025-12-08 14:18:13 +08:00

NextId中不再创建Generator对象

This commit is contained in:
yitter
2022-07-07 22:43:32 +08:00
parent 427bf9d14a
commit 33e6b0a90d
2 changed files with 15 additions and 15 deletions

View File

@@ -39,18 +39,18 @@ namespace Yitter.IdGenerator
/// <returns></returns>
public static long NextId()
{
if (_IdGenInstance == null)
{
lock (_IdGenInstance)
{
if (_IdGenInstance == null)
{
_IdGenInstance = new DefaultIdGenerator(
new IdGeneratorOptions() { WorkerId = 0 }
);
}
}
}
//if (_IdGenInstance == null)
//{
// lock (_IdGenInstance)
// {
// if (_IdGenInstance == null)
// {
// _IdGenInstance = new DefaultIdGenerator(
// new IdGeneratorOptions() { WorkerId = 0 }
// );
// }
// }
//}
return _IdGenInstance.NewLong();
}

View File

@@ -34,9 +34,9 @@ public class YitIdHelper {
* @return
*/
public static long nextId() throws IdGeneratorException {
if (idGenInstance == null) {
idGenInstance = new DefaultIdGenerator(new IdGeneratorOptions((short) 1));
}
//if (idGenInstance == null) {
// idGenInstance = new DefaultIdGenerator(new IdGeneratorOptions((short) 1));
//}
return idGenInstance.newLong();
}