开发者

halt servlet response

I'm facing the following problem. i have a servlet that serves a client request with a video clip. But this video clip is a product of another thread (transcoder). If the clip is not ready to be downloaded because the transcoder thread haven't finished its job, the client request fails! Any suggestions about how to deal with this case? how can i halt the response of the servlet until the transcoded clip is ready by the thread?

开发者_高级运维

Thanks in advance! Antonis


The most straight-forward thing to do here would be to use a Future. Submit request to the transcoder, and let it return a Future immediately. Then the HTTP thread can block on this future calling get until the video is ready.

Joining doesn't sound like a good option to me. Thread#join blocks until the target thread terminates, but whether a thread terminates after doing a job is implementation detail. For example, if the transcoder would use a cached thread pool, the app. breaks.


You can delay the execution of the servlet with the regular means (sleep, wait, join, Future#get).

In your case, it sounds like you want to join the Thread (or get the Future) that transcodes the video.

However, you should really only do this if the time you need to block is just a few seconds. Otherwise, the client browser might time out the request, or the user experience is just bad. If the transcoding work takes longer, consider outputting something like a progress bar, that keeps polling the server until the task is finished and only then tries to load the video clip.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜