Этот метод выдает ошибку при параллельном запуске
Following method :
@Override
@Modifying(clearAutomatically = true)
@Transactional
public void updateCompletedTasksInfo(Task workHistoryTask) {
long start = System.currentTimeMillis();
logger.debug("Start updateCompletedTasksInfo() execution time {} ms", start);
if (StringUtils.isNotBlank(workHistoryTask.getTaskId())) {
Task taskToUpdate = taskIngestionRepo.findByTaskIdAndWarehouseIdAndTenantId(
workHistoryTask.getTaskId(),
workHistoryTask.getTenantId(),
workHistoryTask.getWarehouseId());
if (taskToUpdate != null) {
taskToUpdate.setCompletedPriority(workHistoryTask.getCompletedPriority());
taskToUpdate.setCompletionTime(workHistoryTask.getCompletionTime());
taskToUpdate.setResourceId(workHistoryTask.getResourceId());
taskToUpdate.setDeviceCode(workHistoryTask.getDeviceCode());
taskToUpdate.setDestinationLocation(workHistoryTask.getDestinationLocation());
taskToUpdate.setDestinationLocationTravelSequence(workHistoryTask.getDestinationLocationTravelSequence());
taskToUpdate.setDestinationWorkZone(workHistoryTask.getDestinationWorkZone());
taskToUpdate.setDestinationWorkZoneTravelSequence(workHistoryTask.getDestinationWorkZoneTravelSequence());
if (workHistoryTask.getStartDateTime() != null) {
taskToUpdate.setStartDateTime(workHistoryTask.getStartDateTime());
}
} else {
logger.info("Task {} not found to perform update operation for a warehouse_id {} :: ", workHistoryTask.getTaskId(), workHistoryTask.getWarehouseId());
}
}
long elapsedTime = System.currentTimeMillis() - start;
logger.info(
"Method updateCompletedTasksInfo() for task {} and warehouse {} execution time {} ms ",
workHistoryTask.getTaskId(), workHistoryTask.getWarehouseId(), elapsedTime);
}
'''
is throwing
> org.springframework.dao.CannotAcquireLockException
`org.springframework.dao.CannotAcquireLockException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.LockAcquisitionException: could not execute statement
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Transaction (Process ID 2945) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction`
Please help me in resolving this.