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

  • Home
  • SEARCH
  • 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 113857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:46:07+00:00 2026-05-11T02:46:07+00:00

When running the following Java code, I get very accurate and consistent results in

  • 0

When running the following Java code, I get very accurate and consistent results in determining if the web page I’m testing is up.

protected synchronized boolean checkUrl(HttpURLConnection connection){     boolean error = false;     //HttpURLConnection connection = null;     GregorianCalendar calendar = new GregorianCalendar();      try{         if(connection != null){             connection.connect();              //200 is the expected HTTP_OK response             error = processResponseCode(connection.getResponseCode());              connection.disconnect();         } else{             error = false;         }      }catch(java.net.UnknownHostException uhe){         ...     }      catch(Exception e){         ...     }      return error; } 

The closest match to the Java pattern in c# has much higher results of false positives (mostly due to timeouts – which has a default period of 100000ms).

protected bool connectedToUrl = false;         response = null;          HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(this.getUri());         webreq.Credentials = CredentialCache.DefaultCredentials;         WebResponse res = null;// webreq.GetResponse();          try         {             WebRequest request = WebRequest.Create(this.getUri()) as WebRequest;             request.Credentials = CredentialCache.DefaultCredentials;              if (request != null)             {                 // Get response                  res = webreq.GetResponse();                  connectedToUrl = processResponseCode(res);             }             else             {                 logger.Fatal(getFatalMessage());                  string error = string.Empty;             }         }         catch (Exception e)         {             throw e;         }          return connectedToUrl;     } 

I have tried various patterns in c# to match the effectiveness of the quoted Java code, to no avail.

Any ideas?

  • 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. 2026-05-11T02:46:07+00:00Added an answer on May 11, 2026 at 2:46 am

    Simply change this:

    res = webreq.GetResponse(); connectedToUrl = processResponseCode(res); 

    to

    using (WebResponse res = webreq.GetResponse())  {     connectedToUrl = processResponseCode(res); } 

    (Remove the declaration from earlier.)

    Until you haven’t closed/disposed the response (or it’s been finalized), it’s holding onto the connection. You can only have a certain number (2 by default, I believe) of connections to any one host at a time, hence the timeouts. When you dispose the response, it allows another request to use the same connection.

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

Sidebar

Ask A Question

Stats

  • Questions 188k
  • Answers 188k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Assuming all keys are valid, of course... If the request… May 12, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer I think you should refactor your code in a way… May 12, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer If your DLL is a .Net library just reference it… May 12, 2026 at 5:37 pm

Related Questions

Note I'm running windows, the path just looks like it's linus because I typed
When running the following class the ExecutionService will often deadlock. import java.util.ArrayList; import java.util.Collection;
I'm getting the following error when I try to use the JSTL XML taglib:
I have a problem where I get a deadlock on a MS SQL Server.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.