I want to call REST API by java programming. And I also want to give a time limitation during calling that API. If response time take more than 10 second than I want to disconnect API calling and print a message that response time is more than 10 second.
Please help me by given example code of java.
Given bellow the source code of calling API.
JSONParserPost jsonParserpost = new JSONParserPost();
String output = jsonParserpost.makeHttpRequest(URL, "POST", request);
System.out.println("Row output :"+ output.toString());
JSONObject jsonObject = new JSONObject(output);
if(jsonObject != null)
responeXML = (String)jsonObject.get("response");
Here in 2nd line I've called a REST API. Now I want to fixed a time limit on duration of response of REST API.