使用单例枚举保证流水号工具类为全局单例

This commit is contained in:
wangliwen 2022-07-14 09:35:59 +08:00
parent b27ebec5ba
commit 589f03a103
1 changed files with 18 additions and 3 deletions

View File

@ -25,6 +25,23 @@ public class CodeGenerationUtils {
} }
/**
* 使用单例枚举保证全局单例
*/
enum CodeGenerationUtilsEnum {
INSTANCE;
private CodeGenerationUtils codeGenerationUtils;
CodeGenerationUtilsEnum() {
codeGenerationUtils = new CodeGenerationUtils();
}
public CodeGenerationUtils getInstnce() {
return codeGenerationUtils;
}
}
/** /**
* 生成流程单号 * 生成流程单号
* <p> * <p>
@ -89,9 +106,7 @@ public class CodeGenerationUtils {
} }
private static CodeGenerationUtils codeGenerationUtils = new CodeGenerationUtils();
public static CodeGenerationUtils getInstance() { public static CodeGenerationUtils getInstance() {
return codeGenerationUtils; return CodeGenerationUtilsEnum.INSTANCE.getInstnce();
} }
} }