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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:21:04+00:00 2026-06-12T03:21:04+00:00

This is a schoolwork. I am trying to create peer-to-peer Thread model: http://www.informit.com/articles/article.aspx?p=169479&seqNum=5 Where

  • 0

This is a schoolwork.
I am trying to create peer-to-peer Thread model:

http://www.informit.com/articles/article.aspx?p=169479&seqNum=5

Where the delegation model has a boss thread that delegates tasks to worker threads, in the peer-to-peer model all the threads have an equal working status. Although there is a single thread that initially creates all the threads needed to perform all the tasks, that thread is considered a worker thread and does no delegation. In this model, there is no centralized thread.

So my main thread willl create 5 threads, that start listening to my queue and also create jobs with main thread for 10 seconds. And since all threads must perform tasks, this thread must also wait for jobs. How can I do this?

BlockingQueue<Job> queue = new ArrayBlockingQueue<Job>(1000);

    Collection<Thread> workers = new ArrayList<Thread>();
    for(int i = 0; i < 5; i++) {
        Thread thread = new Thread(new Worker(queue));
        workers.add(thread);
        thread.start();
    }

    long endTime = System.currentTimeMillis() + 10000;
    Random r = new Random();
    while(System.currentTimeMillis() < endTime) {
        try {
            CalculateJob job = new CalculateJob(r.nextInt(50), r.nextInt(50), r.nextInt(50));
            queue.put(job);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }   

So my main thread will be working with creating threads, and workers are just sitting with queue.take().

Do I understand correctly that in peer-to-peer model, every thread must queue.take() or wait for jobs. If so, how can I do this? Any suggestions?

  • 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-12T03:21:05+00:00Added an answer on June 12, 2026 at 3:21 am

    The article you linked to doesn’t say how jobs are created. They probably mean they are created from elsewhere. Looking at the figures for the respective models, we see that:

    • In the “delegation model”, the main thread decides which worker thread will perform the Job
    • In the “peer to peer model”, the peer threads get work from a common queue (and whichever thread happens to be first gets the next Job), so the peer threads coordinate themselves.

    By using a ConcurrentQueue, you have actually implemented the peer to peer model.

    To summarize, the distinction they make is how threads coordinate the work, not how the work is created.

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

Sidebar

Related Questions

This is schoolwork.. I'm trying to create a table that has a default date
This question is in relation to a question I posted yesterday. The link -http://stackoverflow.com/questions/12636348/how-to-add-a-different-class-to-the-same-class-in-jquery
This works. $(document).ready(function(){ $(.items article).click(function(){ window.location=$(this).find(a).attr(href); return false; }); }); However , when the
First of all, this is not schoolwork - just my curiousity as I for
This is my MVC model: public class Link { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid ID {
This is a question I originally posted over at the VideoLan forums ( thread
This problem may seem like school work, but it isn't. At best it is
Premise: This Wikipedia page suggests that the computational complexity of Schoolbook long division is
this is my first question in here, and I would like to ask if
This question is directly related to this SO question I posed about 15 minutes

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.