Springboot API returns overlapping results for parallel run
-
Hi, I am new to springboot. I created an API which run some process that takes around one hour and return the result. The problem is if I submit two process parallel, I am getting the same output. Pls check the below code and give me suggestions --CONTROLLER
@RestController
@RequestMapping("/task")
public class ProcessController {@Autowired TaskRepository taskRepository; @Autowired ProcessService processService; @RequestMapping(value = "/process", method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public Map process(@RequestBody String requestBody) throws Exception { Map result = new LinkedHashMap(); long taskId=0; try { ParameterClass param =null ; JSONObject requestJson = new JSONObject(requestBody); taskId = Long.valueOf(requestJson.getString("taskid")); List lst = taskRepository.findByTaskId(taskId); Task task = lst.stream().filter(p -> p.getParameterName().equals("process\_task")) .findFirst().orElse(null); if (task != null) { String parameterArgs = task.getParameterArg(); param = setParameters(parameterArgs); //Log process take around one hour result = processService.ProcessJob(param); } } catch (Exception ex) { result.put("taskid", taskId); result.put("status", "failed"); result.put("message", ex.getMessage()); ex.printStackTrace(); } finally { return result; } }
}
--SERVICE
@Service
public class ProcessServiceImpl implements ProcessService {//Oracle DB connection private dataLayer dbLayer = null; //Setting the parameters private ProcessParameter inputParam = null; //Storing output private LinkedHashMap outputResult = null; //storing Log details private StringBuilder sbLog = null; @Override public Map ProcessJob(ProcessParameter param) throws Exception { try { outputResult.put("jobid", param.getTask\_id()); outputResult.put("startdate", new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a").format(System.currentTimeMillis())); sbLog.append("taskid= " + param.getTask\_id() + ")\\n"); inputParam = param; // Initialize the dabaLayer object dbLayer = new dataLayer(param.getServer\_name(), param.getDatasource(), param.getUsername(),param.getPassword()); if (!dbLaye
-
Hi, I am new to springboot. I created an API which run some process that takes around one hour and return the result. The problem is if I submit two process parallel, I am getting the same output. Pls check the below code and give me suggestions --CONTROLLER
@RestController
@RequestMapping("/task")
public class ProcessController {@Autowired TaskRepository taskRepository; @Autowired ProcessService processService; @RequestMapping(value = "/process", method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public Map process(@RequestBody String requestBody) throws Exception { Map result = new LinkedHashMap(); long taskId=0; try { ParameterClass param =null ; JSONObject requestJson = new JSONObject(requestBody); taskId = Long.valueOf(requestJson.getString("taskid")); List lst = taskRepository.findByTaskId(taskId); Task task = lst.stream().filter(p -> p.getParameterName().equals("process\_task")) .findFirst().orElse(null); if (task != null) { String parameterArgs = task.getParameterArg(); param = setParameters(parameterArgs); //Log process take around one hour result = processService.ProcessJob(param); } } catch (Exception ex) { result.put("taskid", taskId); result.put("status", "failed"); result.put("message", ex.getMessage()); ex.printStackTrace(); } finally { return result; } }
}
--SERVICE
@Service
public class ProcessServiceImpl implements ProcessService {//Oracle DB connection private dataLayer dbLayer = null; //Setting the parameters private ProcessParameter inputParam = null; //Storing output private LinkedHashMap outputResult = null; //storing Log details private StringBuilder sbLog = null; @Override public Map ProcessJob(ProcessParameter param) throws Exception { try { outputResult.put("jobid", param.getTask\_id()); outputResult.put("startdate", new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a").format(System.currentTimeMillis())); sbLog.append("taskid= " + param.getTask\_id() + ")\\n"); inputParam = param; // Initialize the dabaLayer object dbLayer = new dataLayer(param.getServer\_name(), param.getDatasource(), param.getUsername(),param.getPassword()); if (!dbLaye
This forum is only for bugs and suggestions related to the site. Try asking the question for example in Q&A: [Ask a Question](https://www.codeproject.com/Questions/ask.aspx)
-
This forum is only for bugs and suggestions related to the site. Try asking the question for example in Q&A: [Ask a Question](https://www.codeproject.com/Questions/ask.aspx)