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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:15:05+00:00 2026-06-07T18:15:05+00:00

I am having the following situation: about 10 threads which crawl the web for

  • 0

I am having the following situation:

  • about 10 threads which crawl the web for images
  • all found images must somehow be returned to 10 other threads (for analyzing)

As said, I want to process the images at the same time with the 10 other threads.

Currently I have this Singleton implementation of an own list:

public class ImageList extends Observable implements Iterable<Image> {
    private final BlockingQueue<Image> images = new LinkedBlockingQueue<Image>();

    private static class InstanceHolder {
        public static ImageList instance = new ImageList();
    }

    public static ImageList getInstance() {
        return InstanceHolder.instance;
    }

    private ImageList() {

    }

    public synchronized void execute(Image job) throws InterruptedException {
        images.put(job);

        new Thread(job).start();

        System.out.println("notify observers");
        this.setChanged();
        this.notifyObservers();

        System.out.println(this.countObservers());
    }

    @Override
    public Iterator<Image> iterator() {
        return images.iterator();
    }
}

And as soon as an image is found, I execute ImageList.execute(image), but I do not like this solution, because there is no upper bound to the parallel processes (it might become thousands).

Another idea I had:

  • pass an additional list imagesFound to all my crawlers, let them add all images into that list
  • start 5 threads in the Main class which constantly check for new elements in imagesFound and process them

However, I do not like this solution either, because passing an array which is not really needed by the thread (but just used to pass back found data) seems wrong to me. It might become 20 different lists if I want to search for 20 different informations on a website.

So, how do you usually implement the return of data from threads (in my case: especially if this data itself shall be processed by other threads).

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

    Perhaps a thread pool? Check out ExecutorService.

    • You can set the number of worker threads.
    • It automatically encapsulates a thread-safe work queue.

    Example:

    class Task implements Callable<Object> {
    
        private Image job;
    
        public Task(Image job) {
           this.job = job;
        }
    
        public Object call() {
            // crawl
            return result;
        }
    }
    

    …

    // Initialize thread pool
    ExecutorService exec = Executors.newFixedThreadPool(10);
    
    // every time you get a new job
    Future<Object> result = exec.submit(new Task(job));
    
    // when you want to collect the result
    Object obj = result.get();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having the following situation: I've got a quite complex view from which I've
I'm having following situation. One property object which holds Photos List collection, and Photo
How can i revert a commit having the following situation? Revision 3, Commit Message
I am having following code for getting image from the web: NSURL *ImageURL =
I'm currently having following error message when executing a .sql file with about 26MB
I having one confusion about a particular git behavior: Following are the steps and
The Situation I'm getting the following inconstant behavior on my application: One in about
I've recently come across a situation where I've been a bit confused about which
I'm having an issue with the following situation. User visits site User clicks link
I've been having trouble finding the right design pattern for the following situation: I'm

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.