@@ -34,7 +34,6 @@ namespace Yitter.IdGenerator | |||||
/// <summary> | /// <summary> | ||||
/// 生成新的Id | /// 生成新的Id | ||||
/// 调用本方法前,请确保调用了 SetIdGenerator 方法做初始化。 | /// 调用本方法前,请确保调用了 SetIdGenerator 方法做初始化。 | ||||
/// 否则将会初始化一个WorkerId为1的对象。 | |||||
/// </summary> | /// </summary> | ||||
/// <returns></returns> | /// <returns></returns> | ||||
public static long NextId() | public static long NextId() | ||||
@@ -52,6 +51,8 @@ namespace Yitter.IdGenerator | |||||
// } | // } | ||||
//} | //} | ||||
if (_IdGenInstance == null) throw new ApplicationException("Please initialize Yitter.IdGeneratorOptions first."); | |||||
return _IdGenInstance.NewLong(); | return _IdGenInstance.NewLong(); | ||||
} | } | ||||
@@ -32,7 +32,9 @@ func NextId() int64 { | |||||
// idGenerator = NewDefaultIdGenerator(options) | // idGenerator = NewDefaultIdGenerator(options) | ||||
// } | // } | ||||
//} | //} | ||||
if idGenerator == nil { | |||||
panic("Please initialize Yitter.IdGeneratorOptions first.") | |||||
} | |||||
return idGenerator.NewLong() | return idGenerator.NewLong() | ||||
} | } | ||||
@@ -19,7 +19,6 @@ public class YitIdHelper { | |||||
return idGenInstance; | return idGenInstance; | ||||
} | } | ||||
/** | /** | ||||
* 设置参数,建议程序初始化时执行一次 | * 设置参数,建议程序初始化时执行一次 | ||||
*/ | */ | ||||
@@ -34,9 +33,12 @@ public class YitIdHelper { | |||||
* @return | * @return | ||||
*/ | */ | ||||
public static long nextId() throws IdGeneratorException { | 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)); | |||||
// } | |||||
if (idGenInstance == null) | |||||
throw new IdGeneratorException("Please initialize Yitter.IdGeneratorOptions first."); | |||||
return idGenInstance.newLong(); | return idGenInstance.newLong(); | ||||
} | } | ||||