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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:20:53+00:00 2026-06-04T06:20:53+00:00

I wrote a crawler which uses a user loaded list of words to perform

  • 0

I wrote a crawler which uses a user loaded list of words to perform multiple searches on a site and parse each resulting page.

To achieve this, I wrote a main method which loops through the list of words, sending multiple http get requests asynchronously (using ThreadPool.QueueUserWorkItem) to obtain all pages of results for the current word until no more results are found, and then moves on to the next word.

The callback function accesses a public static class with a static method that parses the returned html and acts accordingly. Right now, I have it locking on the class type each time something accesses the method:

    static class Parser
{
    public static string ResponseAsString(HttpWebResponse response)
    {
        lock (typeof(Parser))
        {
            try
            {
                Stream stream;
                if (response == null || (stream = response.GetResponseStream()) == null) return string.Empty;
                using (var sr = new StreamReader(stream))
                    return sr.ReadToEnd();
            }
            catch { return string.Empty; }
        }
    }

    public static void CallbackMethod_ParseData(string html)
    {
        lock (typeof(Parser))
        {
            //Do some work here
        }
    }
}

So down to my question: how can I more efficiently lock the class and notify waiting threads when the lock is released, or should I not make Parser a static class and instead let each ThreadPool thread instantiate its own instance of this class?

Thanks so much for your help,

-still learning

  • 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-06-04T06:20:54+00:00Added an answer on June 4, 2026 at 6:20 am

    The locks aren’t necessary. Static methods are thread-safe as long as they aren’t sharing static data, which according to your example, they aren’t.

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

Sidebar

Related Questions

I wanna write a crawler to fetch data. from an asp.net site which uses
I wrote a web crawler in Python 2.6 using the Bing API that searches
I wrote simple web site crowler with threadpool. The problem is: then crawler is
Wrote a quick Java proggy to spawn 10 threads with each priority and calculate
I wrote some script in a site. The script makes a new spreadsheet and
I wrote a program which crawls website, processes html pages and stores results in
Hello Guys! I am going to write website crawler, which starts from root address
I once wrote a simple 'crawler' to download http pages for me in JAVA.
I use mechanize gem to crawl websites. I wrote a very simple, one-threaded crawler
I have set a crawler up in Wordpress which grabs stocks data and writes

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.