限定TopOverCostCount范围
This commit is contained in:
@@ -66,7 +66,8 @@ public class SnowWorkerM1 implements ISnowWorker {
|
||||
SeqBitLength = options.SeqBitLength == 0 ? 6 : options.SeqBitLength;
|
||||
MaxSeqNumber = options.MaxSeqNumber <= 0 ? (1 << SeqBitLength) - 1 : options.MaxSeqNumber;
|
||||
MinSeqNumber = options.MinSeqNumber;
|
||||
TopOverCostCount = options.TopOverCostCount == 0 ? 2000 : options.TopOverCostCount;
|
||||
// TopOverCostCount = options.TopOverCostCount == 0 ? 2000 : options.TopOverCostCount;
|
||||
TopOverCostCount = options.TopOverCostCount;
|
||||
_TimestampShift = (byte) (WorkerIdBitLength + SeqBitLength);
|
||||
_CurrentSeqNumber = MinSeqNumber;
|
||||
}
|
||||
@@ -150,11 +151,11 @@ public class SnowWorkerM1 implements ISnowWorker {
|
||||
BeginTurnBackAction(_TurnBackTimeTick);
|
||||
}
|
||||
|
||||
// try {
|
||||
// Thread.sleep(1);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
// Thread.sleep(1);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
return CalcTurnBackId(_TurnBackTimeTick);
|
||||
}
|
||||
@@ -214,7 +215,7 @@ public class SnowWorkerM1 implements ISnowWorker {
|
||||
long tempTimeTicker = GetCurrentTimeTick();
|
||||
|
||||
while (tempTimeTicker <= _LastTimeTick) {
|
||||
try {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
@@ -232,4 +233,3 @@ public class SnowWorkerM1 implements ISnowWorker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.github.yitter.contract.IdGeneratorOptions;
|
||||
import com.github.yitter.core.SnowWorkerM1;
|
||||
import com.github.yitter.core.SnowWorkerM2;
|
||||
|
||||
|
||||
public class DefaultIdGenerator implements IIdGenerator {
|
||||
|
||||
private static ISnowWorker _SnowWorker = null;
|
||||
@@ -40,7 +39,8 @@ public class DefaultIdGenerator implements IIdGenerator {
|
||||
maxWorkerIdNumber = 63;
|
||||
}
|
||||
if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) {
|
||||
throw new IdGeneratorException("WorkerId error. (range:[0, " + (maxWorkerIdNumber > 0 ? maxWorkerIdNumber : 63) + "]");
|
||||
throw new IdGeneratorException(
|
||||
"WorkerId error. (range:[0, " + (maxWorkerIdNumber > 0 ? maxWorkerIdNumber : 63) + "]");
|
||||
}
|
||||
|
||||
// 4.SeqBitLength
|
||||
@@ -62,6 +62,11 @@ public class DefaultIdGenerator implements IIdGenerator {
|
||||
throw new IdGeneratorException("MinSeqNumber error. (range:[5, " + maxSeqNumber + "]");
|
||||
}
|
||||
|
||||
// 7.TopOverCostCount
|
||||
if (options.TopOverCostCount < 0 || options.TopOverCostCount > 10000) {
|
||||
throw new IdGeneratorException("TopOverCostCount error. (range:[0, 10000]");
|
||||
}
|
||||
|
||||
switch (options.Method) {
|
||||
case 2:
|
||||
_SnowWorker = new SnowWorkerM2(options);
|
||||
|
||||
@@ -26,7 +26,7 @@ public class GenTest {
|
||||
long end = System.currentTimeMillis();
|
||||
long time = end - start;
|
||||
|
||||
System.out.println(id);
|
||||
// System.out.println(id);
|
||||
System.out.println("++++++++++++++++++++++++++++++++++++++++WorkerId: "
|
||||
+ WorkerId + ", total: " + time + " ms");
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class StartUp {
|
||||
// options.BaseTime = 1582206693000L;
|
||||
options.Method = method;
|
||||
options.WorkerId = 1;
|
||||
options.TopOverCostCount=2000;
|
||||
// options.TopOverCostCount=2000;
|
||||
|
||||
// 首先测试一下 IdHelper 方法,获取单个Id
|
||||
YitIdHelper.setIdGenerator(options);
|
||||
@@ -39,7 +39,7 @@ public class StartUp {
|
||||
while (true) {
|
||||
genTest.GenStart();
|
||||
Thread.sleep(1000); // 每隔1秒执行一次GenStart
|
||||
System.out.println("Hello World! Java");
|
||||
// System.out.println("Hello World! Java");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user