Я получаю предварительно созданные WorkItems из базы данных и иногда при получении двух запросов получаю одинаковое значение WorkItem, которое вызывает проблему.Мой код выглядит следующим образом: -
private synchronized Long FetchPreCreatedWI(String planName,String queueName) {
Long TrailID = null;
try{
List<Object> preCreatedWI = null;
if("OrderManagement".equalsIgnoreCase(planName)){
preCreatedWI = beanDataManager.executeSQLQuerybyObject("select tec.ENACTMENT_TRAIL_ID from TRAIL_EXECUTION_CONTEXT tec where "
+ "tec.CURRENT_JOB_STATE_NAME ='PREACQUIRED' and tec.CURRENT_QUEUE_NAME = 'PreAcquired' and LAST_USER_COMMENTS is null order by ENACTMENT_TRAIL_ID limit 1");
}else{
preCreatedWI = beanDataManager.executeSQLQuerybyObject("select tec.ENACTMENT_TRAIL_ID from TRAIL_EXECUTION_CONTEXT tec where "
+ "tec.CURRENT_JOB_STATE_NAME ='PREACQUIRED' and tec.CURRENT_QUEUE_NAME ='" + queueName + "' and tec.PLAN_NAME ='" + planName + "' and LAST_USER_COMMENTS is null order by ENACTMENT_TRAIL_ID limit 1");
}
if (!ListUtils.isEmptyList(preCreatedWI)) {
TrailID = Long.parseLong(preCreatedWI.get(0).toString());
if("OrderManagement".equalsIgnoreCase(planName)){
beanDataManager.executeUpdate("update TRAIL_EXECUTION_CONTEXT "
+"inner join SECURITY_SECRESOBJECT sso on sso.ENACTMENT_JOB_ID=TRAIL_EXECUTION_CONTEXT.CURRENT_JOB_ID "
+"inner join SECURITY_ACL4QL saq on saq.SECRESOBJECT_ID = sso.ID "
+"inner join SECURE_JOB_HISTORY sjh on sso.ID = sjh.SECURE_JOB_ID "
+"inner join BEM_FIELDVALUESTRING bfv on TRAIL_EXECUTION_CONTEXT.BEM_ENTITYINSTANCE_ID = bfv.BEM_ENTITYINSTANCE_ID "
+"set TRAIL_EXECUTION_CONTEXT.CURRENT_QUEUE_ID = (select ID from ENACTMENT_QUEUE where queue_name = '"+queueName+"'), "
+"TRAIL_EXECUTION_CONTEXT.CURRENT_QUEUE_NAME = '"+queueName+"', "
+"TRAIL_EXECUTION_CONTEXT.LAST_USER_COMMENTS = 'Job Picked', "
+"saq.QU_ID = (select QU_ID from ENACTMENT_QUEUE where queue_name = '"+queueName+"'), "
+"sjh.OLD_QUEUE_NAME = '"+queueName+"', "
+"bfv.bpi_factValueString005 = '"+queueName+"' "
+"where TRAIL_EXECUTION_CONTEXT.ENACTMENT_TRAIL_ID ="+TrailID);
}else{
beanDataManager.executeUpdate("update TRAIL_EXECUTION_CONTEXT set LAST_USER_COMMENTS = 'Job Picked' where ENACTMENT_TRAIL_ID = "+TrailID);
}
}
}catch(Exception e){
if (logEnabled && logger.isLogLevel(LogLevel.ERROR)) {
logger.log(LogLevel.ERROR, e.getMessage(), e);
}
return TrailID;
}
Как управлять потоком запроса, поэтому, если один запрос был выполнен, он должен выполнить второй без переключения контекста.Как и в запросе на обновление, я изменяю queueName извлеченного WI.