Browse Source

NextId中不再创建Generator对象

tags/v1.3.1
yitter 2 years ago
parent
commit
33e6b0a90d
2 changed files with 15 additions and 15 deletions
  1. +12
    -12
      C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs
  2. +3
    -3
      Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java

+ 12
- 12
C#.NET/source/Yitter.IdGenerator/YitIdHelper.cs 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();
}


+ 3
- 3
Java/source/src/main/java/com/github/yitter/idgen/YitIdHelper.java 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();
}


Loading…
Cancel
Save