Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7674769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:48:43+00:00 2026-05-31T16:48:43+00:00

This is my below code, I am confuse why this thing is happening. In

  • 0

This is my below code, I am confuse why this thing is happening. In this code getLocationTimeout is a method in which I am passing two things- one is the ip address and second is the timeout in milliseconds. So I will get the timeout exception if the response is not getting back in under 5 milliseconds in this particular case. So when I ran this below code, I am getting few timeout exceptions for few ip address. That means some response is taking longer time (greater than 5 ms) but the most important thing that I am confuse about 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. It should have thrown the timeout exception at previous place. 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 = GeoLocationService.getLocationTimeout(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");
    }

}

OUTPUT NOT EXPECTED
Ok. The problem that I am having is- It should print out Timeout Exception for any response greater than 5 milliseconds. But in some case what’s happening is that it is printing Debug but without printing Timeout Exception and with the help of debugger I found that if the difference is around 6 or 8 then I saw pointer entering that if loop of debug.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:48:44+00:00Added an answer on May 31, 2026 at 4:48 pm

    Ok, thanks for adding the info – thought I would put this as a different answer, as its a different tack. So from the info you added I think it just looks like the extra time is just from the extra try catch etc instructions its running (I think). However maybe you should look at redoing the code really. The getLocationByIpTimeout call does all the timing you need I think, so then you can just do whatever logic you need in the catch block, i.e. you don’t need all the timing stuff – will that do what you need?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code below. As you can see I am passing two variables
I saw a below code: Map(1 -> one, 2 -> two) map _._1 this
I have a code like this below, which gives me a $link that equals
So basically in this code I placed below there is a couple things I
This code below is for executing ls -l | wc -l. In the code,
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"
Basically this code below returns the right information, but I need to add the
i am using this code below to dynamically capture the name of the button
Hi I'm using this code below to let a user draw their signature on
i want to put the id into the colorbox below this code nom works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.