1
0
mirror of synced 2025-12-18 19:18:06 +08:00

auto commit

This commit is contained in:
zhouzj
2021-03-22 14:28:26 +08:00
parent d60154b946
commit 3aa9f6f42b
8 changed files with 295 additions and 13 deletions

View File

@@ -29,9 +29,14 @@ public class DefaultIdGenerator implements IIdGenerator {
throw new IdGeneratorException("errorWorkerIdBitLength + SeqBitLength <= 22");
}
if (options.WorkerIdBitLength <= 0)
{
throw new IdGeneratorException("WorkerIdBitLength error.(range:[1, 21])");
}
double maxWorkerIdNumber = Math.pow(2, options.WorkerIdBitLength) - 1;
if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) {
throw new IdGeneratorException("WorkerId error. (range:[1, " + maxWorkerIdNumber + "]");
throw new IdGeneratorException("WorkerId error. (range:[0, " + (maxWorkerIdNumber > 0 ? maxWorkerIdNumber : 63) + "]");
}
if (options.SeqBitLength < 2 || options.SeqBitLength > 21) {

View File

@@ -1,6 +1,7 @@
package com.yitter.test;
import com.yitter.contract.IIdGenerator;
import java.util.HashSet;
import java.util.Set;
@@ -20,14 +21,17 @@ public class GenTest {
public void GenStart() {
long start = System.currentTimeMillis();
long id = 0;
for (int i = 0; i < GenIdCount; i++) {
long id = IdGen.newLong();
id = IdGen.newLong();
// IdSet.add(id);
}
long end = System.currentTimeMillis();
long time = end - start;
System.out.println(id);
System.out.println("++++++++++++++++++++++++++++++++++++++++WorkerId: "
+ WorkerId + ", total: " + time + " ms");

View File

@@ -25,9 +25,9 @@ public class StartUp {
// options.TopOverCostCount = 10000;
// options.WorkerIdBitLength = 6;
// options.SeqBitLength = 9;
// options.MinSeqNumber = 11;
options.WorkerIdBitLength = 6;
options.SeqBitLength = 6;
// options.MinSeqNumber = 5;
// options.MaxSeqNumber = 200;
options.Method = method;
@@ -44,14 +44,13 @@ public class StartUp {
System.out.println("这是用方法 " + method + " 生成的 Id" + newId);
// 然后循环测试一下,看看并发请求时的耗时情况
try
{
try {
while (true) {
genTest.GenStart();
Thread.sleep(1000); // 每隔1秒执行一次GenStart
System.out.println("Hello World!");
System.out.println("Hello World! Java");
}
} catch (InterruptedException e) {
} catch (InterruptedException e) {
e.printStackTrace();
}
}