Future.get () and InterruptedException Asynchronous Streaming

Im using asynchronous streaming in my application using httpClient. I am making a call using Future Api, so

mStrResults = (String) rssFuture.get();

      

this call is trying to fetch the html string returned from my Callable httpClient call () method.

However, I want to ensure that the get method doesn't wait too long when the call () method is executed. Should I pass a timeout parameter when calling rssFuture.get (), or is it okay to block the Exception interrupt?

Also there is a default time that the async thread will wait before InterruptedException is thrown, and if so, can I set a custom value?

+1


source to share


2 answers


You should pass the timeout parameter on call rssFuture.get()

and catch the TimeoutException. InterruptedException will only happen if the thread executing yours call

is interrupted by the method, Thread.interrupt

or if you call the cancel(true)

obj method in the future.



+3


source


You must use Future. get (long timeout, TimeUnit unit) and catch TimeoutException. There is no default timeout for get (), it will always wait.



InterruptedException will not be thrown unless the thread calling Future.get () is interrupted.

+2


source







All Articles