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
Futureimmediately. Then the HTTP thread can block on this future callinggetuntil 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.