according to the information I found on the Internet, it shows that the repetition rate of GUID is very small, but as soon as my project is started recently, there will be repeated GUID generation in a short time. Is there a problem with my code?
the specific code is as follows:
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<TellerDbCore.AccountSubTask.Builder> 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<TellerDbCore.AccountSubTask.Builder> 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;
}
}
}
}
this code generates GUID, through GUID.generateGUID (). ToLowerCase ()
, which is a class method under the oscore-2.2.4.jar
package.