根据我在网上查到资料,表示GUID重复几率很小,但是我这边项目最近一启动,没过多长时间就会有重复的GUID生成,是我代码上面写的有问题吗?
具体代码如下:
public class AccountTaskExecutorTask extends TimerTask {
private static final Logger logger = Logger.getLogger(AccountTaskExecutorTask.class);
private TellerDbCore.AccountTask.Builder aTask = null;
public AccountTaskExecutorTask(TellerDbCore.AccountTask.Builder aTask) {
this.aTask = aTask;
}
public static void schedule(TellerDbCore.AccountTask.Builder aTask) {
Timer timer = new Timer();
timer.schedule(new AccountTaskExecutorTask(aTask), 100L);
}
@Override
public void run() {
try {
process(aTask);
} catch (Exception e) {
logger.error("", e);
}
}
public static void process(TellerDbCore.AccountTask.Builder aTask) {
DataBaseStore dataBaseStore = null;
try {
dataBaseStore = DbHelper.getTransactableDbStore();
invest(aTask, dataBaseStore);
dataBaseStore.commitAndClose();
dataBaseStore = null;
} catch (Exception e) {
logger.error("", e);
if (dataBaseStore != null) {
dataBaseStore.rollbackAndClose();
dataBaseStore = null;
}
}
}
private static void invest(TellerDbCore.AccountTask.Builder theTask, DataBaseStore dataBaseStore) throws Exception {
if (theTask.getProductType() == BtsDbBase.ProductType.PT_NONE_LOCK
|| theTask.getProductType() == BtsDbBase.ProductType.PT_LOCK_3
|| theTask.getProductType() == BtsDbBase.ProductType.PT_LOCK_7) {
switch (theTask.getTaskStatus()) {
case TS_READY:
List subList = AccountTaskHelper.querySubAtByMtId(theTask.getTaskId(), dataBaseStore);
if (subList.size() == 0) {
NewMethods.newAccountSubTask(theTask.getTaskId(), GUID.generateGUID().toLowerCase(),
theTask.getAccountId(), theTask.getProductType(), theTask.getTaskType(), theTask.getAmount(), dataBaseStore);
}
UpdateMethods.updateAccountTask(theTask.getTaskId(), null, BtsDbBase.TaskStatus.TS_PROCESSING, dataBaseStore);
break;
case TS_PROCESSING:
List subTaskList = AccountTaskHelper.querySubAtByMtId(theTask.getTaskId(), dataBaseStore);
if (subTaskList.size() == 1) {
TellerDbCore.AccountSubTask.Builder aSubTask = subTaskList.get(0);
VirtualDbBase.TaskStatus vTs = VirtualConnector.queryTaskStatus(aSubTask.getVrNo(), null);
if (vTs == null) {
VirtualConnector.submitTask(theTask.getAccountId(), BizConstant.VIRTUAL_SYS_INTERMEDIARY,
aSubTask.getAmount() / 100, aSubTask.getVrNo(), VirtualDbBase.TransferType.TT_INVEST,
theTask.getRequestNo());
}
} else {
throw new RuntimeException(ErrCode.SYSTEM_ERROR);
}
break;
case TS_SUCCESSED:
case TS_FAILED:
break;
default:
logger.info( theTask.getTaskStatus());
break;
}
}
}
}
这段代码里面是通过GUID.generateGUID().toLowerCase()来生成GUID,它是oscore-2.2.4.jar包下的类方法。