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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:47:14+00:00 2026-06-07T14:47:14+00:00

In another question on stackoverflow I got a hint that I can use thread

  • 0

In another question on stackoverflow I got a hint that I can use thread pools for the producer-consumer pattern my crawlers are creating.

However, I just cannot find out how to implement it.

In a producer consumer thread on SO they just use the producer consumer to manage the producers and consumers (which in my case would be the crawler themselves; and this is not so much different from my for-loop), but this does not seem the intention of the commentor in my article (as he could not see I used a for loop). The workload is still shared via a queue there.

I also thought about passing a Website object to ExecutorService.submit() with this implementation (and remove Runnable from Crawler):

public class Website implements Runnable {
    private URL url;

    public Website(URL url) {
        this.url = url;
    }

    @Override
    public void run() {
        Crawler crawler = new Crawler();
        crawler.crawl(url);
    }
}

But the problem is that

  1. I think there are too many crawlers being generated
  2. Crawler() expects a queue of already visited websites

How can I properly implement the producer, consumer pattern in my crawler problem? I’m getting totally confused about it all.
I checked so many websites about it on the web and all seem to use it differently.

  • 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-07T14:47:15+00:00Added an answer on June 7, 2026 at 2:47 pm

    I think I will need to see more code in order to understand.
    However, what you can do in order to have producer-consumer is have your Crawler class be a consumer,
    and have the code the uses the executor as a consumer.
    The Crawler will take objects of WebSite from a queue or other shared data structure (synchronized data structure) between the producer and the consumer.
    What you should ask yourself when selecting the data structure is some of the following questions –
    A. Are there priorities among the sites to be crawled?
    If so – consider using a PriorityBlockingQueue.

    B. Is the crawling order important but all priorities are the same?
    If so – consider using a LinkedBlockingQueue

    C. Can you categorize the links somehow?
    If so , maybe you can have several shared data structures, with a map of categories to them.

    I am sure you can come up with many ideas on how to build this shared data structure on you own, these were just my thoughts.

    To conclude –
    1. Have Crawler extend Runnable
    2. Have Crawler extract a “Job” (WebSite class) from a shared data structure (i.e – blocking queue).
    3. Have producer put a job to the shared data structure before using the executor.

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

Sidebar

Related Questions

I see another question on stackoverflow.com whose title seems similar but that doesnot fulfil
From another stackoverflow question, it seems that Android handles large bitmaps differently than other
I got this example from one StackOverflow question that was asked but I couldn't
I plan to ask another question on Stackoverflow but want to use the correct
Another question related to this one . I have a List<SortableObjects> that is the
From another question I recently posted, it seems that Classic ASP might not be
Another question on StackOverflow is asking how this is done, but the general question
I asked another question: https://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python where I was trying to determine the best approach
I run into the same issue described there: Another StackOverflow Question I need to
I have another StackOverflow question on how to install and run a custom checkstyle.

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.