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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:48:40+00:00 2026-06-14T00:48:40+00:00

I want to understand logic of thread pool, and below there is a simple

  • 0

I want to understand logic of thread pool, and below there is a simple incorrect and not full implementation of it:

class ThreadPool {
    private BlockingQueue<Runnable> taskQueue;

    public ThreadPool(int numberOfThreads) {
        taskQueue = new LinkedBlockingQueue<Runnable>(10);

        for (int i = 0; i < numberOfThreads; i++) {
            new PoolThread(taskQueue).start();
        }
    }

    public void execute(Runnable task) throws InterruptedException {
        taskQueue.put(task);
    }
}


class PoolThread extends Thread {
    private BlockingQueue<Runnable> taskQueue;

    public PoolThread(BlockingQueue<Runnable> queue) {
        taskQueue = queue;
    }

    public void run() {
        while (true) {
            try {
                taskQueue.take().run();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

What if the number of threads to execute exceed the taskQueue size, will the calling thread be blocked?ThreadPoolExecutor – here we can see that in this case it’s a work of rejected execution handler, but I still can not understand how does it work. Thanks in advance for any help.

EDIT:

set max size of blocking queue to 10

  • 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-14T00:48:41+00:00Added an answer on June 14, 2026 at 12:48 am

    What if the number of threads to execute exceed the taskQueue size, will the calling thread be blocked?

    The size of the queue is the number of tasks which are NOT running. Typically it will be empty even when the threads are busy. Having a queue length which matches the number of threads has no significance and nothing special happens at this point.

    here we can see that in this case it’s a work of rejected execution handler

    The rejection handler is only called if the queue is full. Your queue has no limit so it wouldn’t be called even if you supported this feature.

    However, if it did have a limit and it supported this feature, the typical behaviour is to throw an exception. You can make it do other things such as block, have the current thread run the task (which is my preference) or ignore the task.

    I still can not understand how does it work.

    When you offer() a task to a queue, it return false if the queue could not accept it. When this happens call the rejected execution handler.

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

Sidebar

Related Questions

I want to understand the logic of authorization,cookies,users logins,sessions..Do you know any source that
I don't just understand their logic. The YUI site says that the full suite
I'm neophyte in obj-c, so I cant understand some of this logic. I want
I am trying to implement thread pool in C++ using pthread. I want to
I want to understand the reason and/or core-logic for JSONObject is being an un-ordered
is there a way to understand the following logic contained in the splitting pattern:
I’m learning cocoa (not ios) and I want to understand and implement MVC in
I want to understand the role interface plays in inheritance between two classes. My
I want to understand the actual theory behind types rather than just learning about
I want to understand in which order are the elements of h_addr_list sorted when

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.