Skip to content

Commit c49bffa

Browse files
committed
Merge branch '3.5.x'
2 parents 804fe13 + 31357da commit c49bffa

File tree

1 file changed

+10
-5
lines changed
  • framework/ohscript/src/main/java/modelengine/fit/ohscript/util

1 file changed

+10
-5
lines changed

framework/ohscript/src/main/java/modelengine/fit/ohscript/util/Tool.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import modelengine.fit.ohscript.script.parser.nodes.FunctionDeclareNode;
1717
import modelengine.fit.ohscript.script.semanticanalyzer.type.expressions.TypeExprFactory;
1818
import modelengine.fitframework.beans.ObjectInstantiator;
19+
import modelengine.fitframework.util.LockUtils;
1920
import modelengine.fitframework.util.ObjectUtils;
2021

2122
import net.bytebuddy.ByteBuddy;
@@ -36,7 +37,9 @@
3637
* @since 1.0
3738
*/
3839
public class Tool {
39-
private static AtomicLong id = new AtomicLong(1); // remove static
40+
private static final Object lock = LockUtils.newSynchronizedLock();
41+
42+
private static AtomicLong id = new AtomicLong(1);
4043

4144
/**
4245
* 打印警告信息
@@ -73,9 +76,11 @@ protected static void setId(long value) {
7376
/**
7477
* 初始化id,只有在id为非正数时生效
7578
*/
76-
private static synchronized void initId() {
77-
if (id.get() <= 0) {
78-
setId(1);
79+
private static void initId() {
80+
synchronized (lock) {
81+
if (id.get() <= 0) {
82+
setId(1);
83+
}
7984
}
8085
}
8186

@@ -96,7 +101,7 @@ public static void grammarError(String info) {
96101
* @return 返回生成的UUID
97102
*/
98103
public static String uuid() {
99-
return UUIDUtil.fastUuid();
104+
return String.valueOf(newId());
100105
}
101106

102107
/**

0 commit comments

Comments
 (0)