java - Timeout Rest service -


i working on rest service. service retrieves information legacy third party system using proprietary protocol abstracted api exposed noway set sort of timeout on calls system. system slows down load on service increases.

is there way service send default response if operation takes long?. suggestion on how tackle issue appreciated?

you can wrap code block makes api request thread , use future timeout request.

here example how it;

https://stackoverflow.com/a/15120935/975816

after timeout; implement exceptions , set default response in catch block;

string response;  try {    response = future.get(5, timeunit.minutes);  } catch (interruptedexception ie) {    /* handle interruption. or ignore it. */   response = "default interrupted response"; } catch (executionexception ee) {    /* handle error. or ignore it. */   response = "default exception response"; } catch (timeoutexception te) {    /* handle timeout. or ignore it. */   response = "default timeout response";  } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -