How to handle long running web service operations?

我的未来我决定 提交于 2019-11-29 18:02:20

问题


I have to create a Java EE application which converts large documents into different formats. Each conversion takes between 10 seconds and 2 minutes. The SOAP requests will be made from a client application which I also have to create.

What's the best way to handle these long running requests? Clearly the process takes to much time to run without any feedback to the user.

I can think of the following ways to provide some kind of feedback, but I'm not sure if there isn't a better way, perhaps something standardized.

  1. The client performs the request from a thread and the server sends the document in the response, which can take a few minutes. Until then the client shows a "Please wait" message, progress spinner, etc. (This seems to be simple to implement.)
  2. The client sends a "Start conversion" command. The server returns some kind of job ID which the client can use to frequently poll for a status update or the final document. (This seems to be user friendly, because I can display a progress, but also requires the server to be stateful.)
  3. The client sends a "Start conversion" command. The server somehow notifies the client when it is done. (Here I don't even know how to do this)

Are there other approaches? Which one is the best in terms of performance, stability, fault tolerance, user-friendliness, etc.?

Thank you for your answers.


回答1:


Since this almost all done server-side, there isn't much a client can do besides poll the server somehow for updates on the status.

#1 is OK, but users get impatient really fast. "A few minutes" is a bit too long for most people. You'd need HTTP Streaming to implement #3, but I think that's overkill.

I would just go with #2.




回答2:


For 3 the server should return a unique ID back to the client and using that ID the client has to ask the server the result at a later time



来源:https://stackoverflow.com/questions/3378756/how-to-handle-long-running-web-service-operations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!