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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:46:45+00:00 2026-05-26T00:46:45+00:00

I have seen the thread pool executor implementation and the rejected execution policies that

  • 0

I have seen the thread pool executor implementation and the rejected execution policies that it provides. However, I have a custom requirement – I want to have a call back mechanism where in I get notifications when the queue size limit is reached and say when the queue size reduces to say 80 % of the max allowed queue size.

public interface ISaturatedPoolObserver {
 void onSaturated(); // called when the blocking queue reaches the size limit
 void onUnsaturated(); // called when blocking queues size goes below the threshold.
}

I feel that this can be implemented by subclassing thread pool executor, but is there an already implemented version? I would be happy to add more details and my work so far as and when needed to provide clarity.

  • 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-05-26T00:46:46+00:00Added an answer on May 26, 2026 at 12:46 am

    I want to have a call back mechanism where in I get notifications when the queue size limit is reached…

    I wouldn’t subclass the executor but I would subclass the BlockingQueue that is used by the executor. Something like the following should work. There are race conditions in the code around the checkUnsaturated() if you remove an entry and someone puts one back in. You might have to synchronize on the queue if these need to be perfect. Also, I have no idea what methods the executor implementations use so you might not need to override some of these.

    public class ObservableBlockingQueue<E> extends LinkedBlockingQueue<E> {
         private ISaturatedPoolObserver observer;
         private int capacity;
         public ObservableBlockingQueue(ISaturatedPoolObserver observer,
             int capacity) {
             super(capacity);
             this.observer = observer;
             this.capacity = capacity;
        }
        @Override
        public boolean offer(E o) {
            boolean offered = super.offer(o);
            if (!offered) {
                observer.onSaturated();
            }
            return offered;
        }
        @Override
        public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException {
            boolean offered = super.offer(o, timeout, unit);
            if (!offered) {
                observer.onSaturated();
            }
            return offered;
        }
        @Override
        public E poll() {
            E e = super.poll();
            if (e != null) {
                 checkUnsaturated();
            }
            return e;
        }
        @Override
        public E poll(long timeout, TimeUnit unit) throws InterruptedException {
            E e = super.poll(timeout, unit);
            if (e != null) {
                 checkUnsaturated();
            }
            return e;
        }
        @Override
        public E take() throws InterruptedException {
            E e = super.take();
            checkUnsaturated();
            return e;
        }
        @Override
        public boolean remove(E e) throws InterruptedException {
            boolean removed = super.remove(e);
            if (removed) {
                checkUnsaturated();
            }
            return removed;
        }
        private void checkUnsaturated() {
            if (super.size() * 100 / capacity < UNSATURATED_PERCENTAGE) {
                observer.onUnsaturated();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen a number of examples that have a thread procedure that looks like
I know that .NET lambda expressions can capture outer variables. However, I have seen
Playing with log4net, I have seen the possibility to use a per-thread stack of
Where is the TickCount() call? I have seen several threads on the web that
I have a main thread that contains my WPF GUI and one or more
I have seen this thread on how to execute terminal commands from within a
I have a custom object that implements INotifyPropertyChanged. I have a collection of these
I have seen this thread: WPF image resources and applied the information there. But
I've seen articles on ::std::thread and ::std::forward and such, but I have seen no
I have seen other thread with similar issue but was not able to work

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.