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 4552154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:44:23+00:00 2026-05-21T16:44:23+00:00

I am trying to crawl 300,000 URLs. However, somewhere in the middle, the code

  • 0

I am trying to crawl 300,000 URLs. However, somewhere in the middle, the code hangs when trying to retrieve the response code from a URL. I am not sure what is going wrong since a connection is being established but the problem is occurring after that. I have modified the code setting the read time out and the request property as suggested.However, even now the code is unable to obtain the response code!
Any suggestions/pointers will be greatly appreciated. Also, is there any way to ping a website for a certain time period and if it’s not responding just proceed to the next one?

Here is my modified code snippet:

URL url=null;

try
{
   Thread.sleep(8000);
}
catch (InterruptedException e1)
{
   e1.printStackTrace();
}

 try
{
   //urlToBeCrawled comes from the database
   url=new URL(urlToBeCrawled);
}
catch (MalformedURLException e)
{
   e.printStackTrace();
 //The code is in a loop,so the use of continue.I apologize for putting code in the catch block.
  continue;
}
 HttpURLConnection huc=null;
 try
{
   huc = (HttpURLConnection)url.openConnection();

}
catch (IOException e)
{
   e.printStackTrace();
}
 try
 {
    //Added the request property
   huc.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
  huc.setRequestMethod("HEAD");

 }
 catch (ProtocolException e)
 {
    e.printStackTrace();
 }

 huc.setConnectTimeout(1000);
 try
 {
    huc.connect();

  }
 catch (IOException e)
 {

    e.printStackTrace();
    continue;
  }

 int responseCode=0;
 try
 {
   //Sets the read timeout
   huc.setReadTimeout(15000);
   //Code hangs here for some URL which is random in each run
   responseCode = huc.getResponseCode();

  }
 catch (IOException e)  
{
   huc.disconnect();

   e.printStackTrace();
   continue;
}
if (responseCode!=200)
{
   huc.disconnect();
   continue;
 }
  • 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-21T16:44:24+00:00Added an answer on May 21, 2026 at 4:44 pm

    It is hanging because the response code was never received in the byte stream. You will want to look at an http debugger and see what was actually received, if anything at all. It did however appear to open the TCP connection to the server. It might not like your user-agent (which may not have been set to what you think it was) or the request method of HEAD, or it could be a server with limited bandwidth. You could use Socket class to just open a connection and ready the bytes in manually to see what you are/aren’t recieving.

    On a side note, using only Socket is not actually a bad approach depending on what you want to do. It sounds like you are writing an http server checker, in which case you will get more functionality out of using just Socket directly as you will be able to engineer better and much more optimized techniques (you are working with a large volume of low level network io after all).

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

Sidebar

Related Questions

I'm trying to crawl about a thousand of web sites, from which I'm interested
I am trying to write my own version of Crawl.java from Nutch where I'd
I'm trying to get crawl to work on two separate farms I have but
Trying to perform a single boolean NOT operation, it appears that under MS SQL
Iam trying to configure nutch for running multi-threaded crawling. However , Iam facing an
I'm trying to find the best method to gather URLs, I could create my
What i'm trying to do is crawl this webpage using C# http://www.madisonhonda.com/Preowned-Inventory.aspx?layout=layout1# What I
Trying to learn ASP MVC coming from Linux/LAMP background (in other words I'm a
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to get my css / C# functions to look like this: body {

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.