I have to write a java method for a webservice. The java method will take few parameters and then start some time consuming data processing.
My requirement is that I want to immediately return a unique Id to the calling method from my java method and do the data processing in background. The caller method will keep checking the status of data processing with unique id in between.
What could be the best way to return uniqueId from method while keep doing data processing in background. Is using thread good idea or any other solution is also there?
e.g.
main method() {
string uniqueId = dataProcessing(params);
}
dataProcessing(params) {
String uniqueId = uniqueIdGenerator();
doDataProcessing();
return uniqueId;
}
In above method uniqueId will be returned only when doDataProcessing method completes job. What could be the best way to first return uniqueId and then do background processing of data.