Timeout Exceptions

Posted by Raihan Jamal on Stack Overflow See other posts from Stack Overflow or by Raihan Jamal
Published on 2012-03-19T01:58:46Z Indexed on 2012/03/19 2:04 UTC
Read the original article Hit count: 201

Filed under:

This is my below code, I am confuse why this thing is happening. In this code getLocationByIpTimeout is a method in which I am passing two things- one is the ip address and second is the timeout. So I will get the timeout exception if the response is not getting back in under 5 ms. So when I ran this below code, I am getting few timeout exceptions but the most important thing that I am confuse is if I am getting timeout exceptions (time taken to get the response is greater than 5 ms) then why the program is entering in that if loop in which I am having difference > 5. What can be the possible reason for this? It is because of catch block?? Any suggestions will be appreciated.

            long runs =10000;
            long difference = 0;

            while(runs > 0) {
            String ipAddress = generateIPAddress();

            long start_time = System.nanoTime();

            try {
                resp = PersonalizationGeoLocationServiceClientHelper.getLocationByIpTimeout(ipAddress, 5);
                } catch (TimeoutException e) {
                    System.out.println("Timeout Exception");
                }


                long end_time = System.nanoTime();

                if(resp == null || (resp.getLocation() == null)) {
                    difference  = 0;
                } else if(resp.getLocation() != null) {
                    difference = (end_time - start_time)/1000000;
                }

                if(difference> 5) {
                    System.out.println("Debug");
                }

                }

© Stack Overflow or respective owner

Related posts about java