mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 03:58:33 +08:00
fix: 尝试解决任务编号重复问题
https://github.com/metersphere/metersphere/issues/34056
This commit is contained in:
parent
298208d0ef
commit
1aaa6c3515
@ -37,14 +37,19 @@ public class NumGenerator {
|
||||
*/
|
||||
public static long nextNum(String prefix, ApplicationNumScope scope) {
|
||||
RIdGenerator idGenerator = redisson.getIdGenerator(prefix + "_" + scope.name());
|
||||
|
||||
// 二级的用例
|
||||
if (SUB_NUM.contains(scope)) {
|
||||
// 每次都尝试初始化,容量为1,只有一个线程可以初始化成功
|
||||
idGenerator.tryInit(1, LIMIT);
|
||||
if (!idGenerator.isExists()) {
|
||||
idGenerator.tryInit(1, LIMIT);
|
||||
}
|
||||
return Long.parseLong(prefix.split("_")[1] + StringUtils.leftPad(String.valueOf(idGenerator.nextId()), 3, "0"));
|
||||
} else {
|
||||
// 每次都尝试初始化,容量为1,只有一个线程可以初始化成功
|
||||
idGenerator.tryInit(INIT, LIMIT);
|
||||
if (!idGenerator.isExists()) {
|
||||
idGenerator.tryInit(INIT, LIMIT);
|
||||
}
|
||||
return idGenerator.nextId();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user