Java get Response time of GET Restful Service -


i have 1 get restful service return json. have response time of service. requirement when try json data service , if service take more 10 seconds have redirect page. how can this?

my code given below

import java.net.url; import java.net.httpurlconnection;  url url = new url(surl); httpurlconnection req = (httpurlconnection) url.openconnection(); req.connect();  if (req.getresponsecode() == httpurlconnection.http_ok) {     system.out.println("responsecode = http_ok"); } 

i using java eclipse mars 1.

first set timeout , catch timeout exception , make new request:

try {     req.setconnecttimeout(timeunit.seconds.tomillis(10));      req.setreadtimeout(timeunit.seconds.tomillis(10));      [...] readdata(req);  } catch (sockettimeoutexception e) {     // request again } 

edit: readtimeout optional. i'm using bacause want wait long data.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -