0

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.

Neeraj
  • 1,776
  • 2
  • 16
  • 35

1 Answers1

0

Yeap, you I think thread can be used and it is a good choice for your background task. But I suggest not to do anything from scratch. You are working on webservice, probably you are using some framework and let the framework handle it. Because they are tested and used by many other people. So they are much reliable instead of using own method.

Razib
  • 10,965
  • 11
  • 53
  • 80
  • I am using CXF restful webservice. In webservice first request client sends me parameter and expects a uniqueId. I need to first send unique id and then start the dataprocessing. Is it possible with CXF? – Neeraj Feb 15 '15 at 18:50