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

swift - Button on Table View Cell connected to local function -

dns - Dokku server hosts two sites with TLD's, both domains are landing on only one app -

c# - ajax - How to receive data both html and json from server? -