Android - Set HttpResponse timeout in Java

I have created the following function for checking the connection status

private void checkConnectionStatus() {
HttpClient httpClient = new DefaultHttpClient();

try {
String url = "http://xxx.xxx.xxx.xxx:8000/GaitLink/"
+ strSessionString + "/ConnectionStatus";
Log.d("phobos", "performing get " + url);
HttpGet method = new HttpGet(new URI(url));
HttpResponse response = httpClient.execute(method);

if (response != null) {
String result = getResponse(response.getEntity());
...

When I shut down the server for testing the execution waits a long time at lineHttpResponse response = httpClient.execute(method);

Does anyone know how to set the timeout in order to avoid waiting too long?

Popular Posts